#include <iostream>
#include <fstream>
#include <complex>
#include <vector>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>

#define iset(t) __gnu_pbds::tree<t, __gnu_pbds::null_type, less<t>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>

#define V vector
#define P pair
#define F first
#define S second

#ifdef LOC
#define $(x) x
#define clog(x) clog << x
#else
#define $(x)
#define clog(x)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<int> ci;
typedef complex<ll> cll;
typedef complex<ld> cld;
typedef P<int, int> pi;
typedef P<ll, ll> pll;
typedef V<bool> vb;
typedef V<int> vi;
typedef V<ll> vll;

int n, q;
vi a;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifdef STR
    freopen("ti.txt", "r", stdin);
    freopen("tm.txt", "o", stdout);
    #endif

    cin >> n >> q;
    a.resize(n);
    for (auto &x : a) cin >> x;

    iset(int) c, d;
    
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) c.insert(i);
        else d.insert(i);
    }

    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;

        if (t == 1) {
            int x;
            cin >> x;
            x--;

            if (a[x] == 1) c.erase(x);
            else d.erase(x);
            if (a[x+1] == 1) c.erase(x+1);
            else d.erase(x+1);

            swap(a[x], a[x+1]);

            if (a[x] == 1) c.insert(x);
            else d.insert(x);

            if (a[x+1] == 1) c.insert(x+1);
            else d.insert(x+1);
        } else {
            int y;
            cin >> y;
            y--;

            if (a[0] == 1) {
                if (a[y] == 1) {
                    int z = c.order_of_key(y);
                    cout << z + min(z, (int)d.size()) + 1 << "\n";
                } else {
                    int z = d.order_of_key(y);
                    cout << z + min(z+1, (int)c.size()) + 1 << "\n";
                }
            } else {
                if (a[y] == 2) {
                    int z = d.order_of_key(y);
                    cout << z + min(z, (int)c.size()) + 1 << "\n";
                } else {
                    int z = c.order_of_key(y);
                    cout << z + min(z+1, (int)d.size()) + 1 << "\n";
                }
            }
        }
    }

    return 0;
}