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

#ifndef LOCAL
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
#endif

signed main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
#ifdef LOCAL
    freopen("./../input.txt", "r", stdin);
#endif
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (auto& x : a) cin >> x;
    vector<vector<int>> b(2);
    vector<int> pos(n);
    for (int i = 0; i < n; i++) {
        a[i]--;
        pos[i] = b[a[i]].size();
        b[a[i]].push_back(i);
    }
    while (q--) {
        int t, x;
        cin >> t >> x;
        x--;
        if (t == 1) {
            if (a[x] == a[x + 1])
                continue;
            int p1 = pos[x];
            int p2 = pos[x + 1];
            swap(b[a[x]][p1], b[a[x + 1]][p2]);
            swap(pos[x], pos[x + 1]);
            swap(a[x], a[x + 1]);
            continue;
        }
        int pl = pos[x] + (!b[a[x] ^ 1].empty() && b[a[x]][0] > b[a[x] ^ 1][0]);
        cout << 1 + pos[x] + min((int)b[a[x] ^ 1].size(), pl) << "\n";
    }
    return 0;
}