#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using oset = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;


/*
struct segtree{
    vector<ll> tree;
    ll sz;
    ll def = 0;
    ll merg(ll a, ll b) {
        return a + b;
    }
    void clar(ll n) {
        tree.assign(4 * n, def);
        sz = n;
    }
    segtree() {

    }
    void build(ll v, ll l, ll r, vector<ll> & a) {
        if (r - l == 1) {
            tree[v] = a[l];
            return;
        }
        ll m = (l + r) / 2;
        build(v * 2 + 1, l, m, a);
        build(v * 2 + 2, m, r, a);
        tree[v] = merg(tree[v * 2 + 1], tree[v * 2 + 2]);
    }
    segtree(vector<ll> & a) {
        ll n = (ll)a.size();
        clar(n);
        build(0, 0, sz, a);
    }
};
*/


void solve() {
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (auto & i : a) {
        cin >> i;
        i--;
    }
    oset vsp0;
    oset vsp1;
    for (ll i = 0; i < n; i++) {
        if (a[i] == 0) {
            vsp0.insert(i);
        } else {
            vsp1.insert(i);
        }
    }
    while (q--) {
        ll t;
        cin >> t;
        if (t == 1) {
            ll x;
            cin >> x;
            x--;
            if (a[x] != a[x + 1]) {
                if (a[x] == 0) {
                    vsp0.erase(x);
                } else {
                    vsp1.erase(x);
                }
                if (a[x + 1] == 0) {
                    vsp0.erase(x + 1);
                } else {
                    vsp1.erase(x + 1);
                }
                swap(a[x], a[x + 1]);
                if (a[x] == 0) {
                    vsp0.insert(x);
                } else {
                    vsp1.insert(x);
                }
                if (a[x + 1] == 0) {
                    vsp0.insert(x + 1);
                } else {
                    vsp1.insert(x + 1);
                }
            }
        } else {
            ll v;
            cin >> v;
            v--;
            ll cr = min(vsp0.size(), vsp1.size());
            ll col = a[v];
            ll num = 0;
            if (col == 0) {
                num = vsp0.order_of_key(v);
            } else {
                num = vsp1.order_of_key(v);
            }
            if (num < cr) {
                if (col == a[0]) {
                    cout << num * 2 + 1 << endl;
                } else {
                    cout << num * 2 + 2 << endl;
                }
            } else {
                cout << num + cr + 1 << endl;
            }
        }
    }
}

signed main() {
    ll MULTITEST = 0;
    #ifdef zapvm
        MULTITEST = 1;
        freopen("in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    if (MULTITEST) {
        cin >> t;
    }
    while (t--) {
        solve();
    }
}