#include <bits/stdc++.h>
using namespace std;

#define int int_fast64_t
#define ull unsigned long long
#define all(x) x.begin(), x.end()
mt19937 rng(127);

constexpr int MAXN = 1e4 + 1, INF = 2e9, MOD = 998244353, k1 = 31;
// constexpr int interesno_zabanyat_li_menya_prosto_za_stroku_v_reshenii_MOD = 435397531;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    queue<int> e, d;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 1) {
            e.push(i);
        } else {
            d.push(i);
        }
    }
    vector<int> ans(n);
    int p = 0, lst = -1;
    while (d.size() * e.size()) {
        if (lst == 1) {
            ans[d.front()] = p;
            p++;
            lst = a[d.front()];
            d.pop();
        } else {
            ans[e.front()] = p;
            p++;
            lst = 1;
            e.pop();
        }
    }
    while (!d.empty()) {
        ans[d.front()] = p;
        p++;
        d.pop();
    }
    while (!e.empty()) {
        ans[e.front()] = p;
        p++;
        e.pop();
    }
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int x;
            cin >> x,x--;
            if (x == 0 || (a[x] == a[x + 1])) {

            } else {
                swap(ans[x], ans[x + 1]);
            }
            swap(a[x], a[x + 1]);
        } else {
            int x;
            cin >> x,x--;
            cout << ans[x] + 1 << '\n';
        }
    }
    return 0;
}