#include <bits/stdc++.h>

using namespace std;

#define sll __int128_t
#define ll long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define size(x) (int)(x).size()

const int MOD = 998244353, MAXN = 5e5 + 100, inf = 1e9;

int add(int a, int b) {
    if (a + b >= MOD) {
        return a + b - MOD;
    }
    return a + b;
}

int sub(int a, int b) {
    if (a - b < 0) {
        return a - b + MOD;
    }
    return a - b;
}

int mult(int a, int b) {
    return ((ll)a * b) % MOD;
}

int kv(int a) {
    return ((ll)a * a) % MOD;
}

int fast_pow(int x, int a) {
    if (a == 0) return 1;
    if (a == 1) return x;
    if (a & 1) return fast_pow(x, fast_pow(x, a - 1));
    return kv(fast_pow(x, a / 2));
}

int d1[MAXN];
int d2[MAXN];
int a[MAXN];

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> c(2);
    vector<int> num(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i]; a[i]--;
        num[i] = c[a[i]]++;
    }
    c[0]--; c[1]--;
    for (int i = 0; i < q; i++) {
        int t, x;
        cin >> t >> x;
        x--;
        if (t == 2){
            if (a[x] == a[0]) {
                if (c[a[x]] <= c[1 - a[x]]) {
                    cout << c[a[x]] * 2 - 1 << "\n";
                }
                else cout << c[1 - a[x]] * 2 + c[a[x]] - c[1 - a[x]] << "\n";
            }
            else {
                if (c[a[x]] <= c[1 - a[x]]) {
                    cout << c[a[x]] * 2 << "\n";
                }
                else cout << c[1 - a[x]] * 2 + c[a[x]] - c[1 - a[x]] << "\n";
            }
        }
        else {
            swap(a[i], a[i + 1]);
        }
    }

}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int ttt = 1;
    //cin >> ttt;
    while (ttt--) {
        solve();
    }
}