#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll inf = 2e18;
const ld eps = 1e-13;
using vl = vector<ll>;
using vvl = vector<vl>;
const int block_sz = 450;
struct Segtree {
    struct Node {
        ll min;
    };
    Node null {
        inf
    };
    vector<ll> a;
    vector<Node> t;
    Segtree(vector<ll> &a_) {
        a = a_;
        t.assign((ll)a.size() * 4, null);
        build(0, 0, (ll)a.size());
    }
    Node mergee(Node a, Node b) {
        Node ans;
        ans.min = min(a.min, b.min);
        return ans;
    }
    void build(ll v, ll tl, ll tr) {
        if (tl + 1 == tr) {
            t[v].min = a[tl];
            return;
        }
        ll tm = (tl + tr) / 2;
        build(v*2+1, tl, tm);
        build(v*2+2, tm, tr);
        t[v] = mergee(t[v*2+1], t[v*2+2]);
    }
    void ins(ll v, ll indx, ll val, ll tl, ll tr) {
        if (tl + 1 == tr) {
            t[v].min = val;
            return;
        }
        ll tm = (tl + tr) / 2;
        if (tm > indx) {
            ins(v*2+1, indx, val, tl, tm);
        } else {
            ins(v*2+2, indx, val, tm, tr);
        }
        t[v] = mergee(t[v*2+1], t[v*2+2]);
    }
    Node query(ll v, ll l, ll r, ll tl, ll tr) {
        if (l >= tr || tl >= r) return null;
        if (tl + 1 == tr) return t[v];
        ll tm = (tl + tr) / 2;
        return mergee(query(v*2+1, l, r, tl, tm), query(v*2+2, l, r, tm, tr));
    }
};
int main() {
//    ios::sync_with_stdio(0); cin.tie(0);
    ll n, q; cin >> n >> q;
    vector<ll> help(n);
    for (auto &i : help) cin >> i;
    vector<ll> ass_1, ass_2;
    for (ll i = 0; i < n; i++) {
        if (help[i] == 1) {
            ass_1.push_back(i);
        } else {
            ass_2.push_back(i);
        }
    }
    while (q--) {
//        for (auto &i : ass_1) cout << i << " ";
//        cout << "\n";
//        for (auto &i : ass_2) cout << i << " ";
//        cout << "\n";
        ll tp; cin >> tp;
        if (tp == 2) {
            ll indx; cin >> indx;
            indx--;
            ll type = help[indx];
            ll cnt = 0;
            if (type == 2) {
                if (help[0] == 1) {
                    cnt = lower_bound(ass_2.begin(), ass_2.end(), indx) - ass_2.begin() + 1;
                    ll pluss = min((ll)ass_1.size(), max(0LL, cnt));
                    cnt += pluss;
                } else {
                    cnt = lower_bound(ass_2.begin(), ass_2.end(), indx) - ass_2.begin() + 1;
                    ll pluss = min((ll)ass_1.size(), max(0LL, cnt - 1));
                    cnt += pluss;
                }
            } else {
                if (help[0] == 2) {
                    cnt = lower_bound(ass_1.begin(), ass_1.end(), indx) - ass_1.begin() + 1;
                    ll pluss = min((ll)ass_2.size(), max(0LL, cnt));
                    cnt += pluss;
                } else {
                    cnt = lower_bound(ass_1.begin(), ass_1.end(), indx) - ass_1.begin() + 1;
                    ll pluss = min((ll)ass_2.size(), max(0LL, cnt - 1));
                    cnt += cnt + pluss;
                }
            }
            cout << cnt << "\n";
        } else {
            ll indx; cin >> indx;
            indx--;
            ll type1 = help[indx];
            ll type2 = help[indx + 1];
            if (type1 == 1) {
                ll it = lower_bound(ass_1.begin(), ass_1.end(), indx) - ass_1.begin();
                ass_1[it]++;
            } else {
                ll it = lower_bound(ass_2.begin(), ass_2.end(), indx) - ass_2.begin();
                ass_2[it]++;
            }
            if (type2 == 1) {
                ll it = lower_bound(ass_1.begin(), ass_1.end(), indx) - ass_1.begin();
                ass_1[it]--;
            } else {
                ll it = lower_bound(ass_2.begin(), ass_2.end(), indx) - ass_2.begin();
                ass_2[it]--;
            }
            swap(help[indx], help[indx + 1]);
        }
    }
}
