#include<bits/stdc++.h>

using namespace std;

#define int long long

const int eps = 998244353;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> pref(n + 1);
    pref[0] = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 1) {
            pref[i + 1] = pref[i] + 1;
        }
        else {
            pref[i + 1] = pref[i];
        }
    }
    for (int i = 0; i < q; i++) {
        int f;
        cin >> f;
        if (f == 1) {
            int x;
            cin >> x;
            if (a[x] != a[x - 1]) {
                if (a[x - 1] == 1) {
                    pref[x] -= 1;
                }
            }
            swap(a[x], a[x - 1]);
        }
        else {
            int x;
            cin >> x;
            int one = pref[x - 1];
            int two = x - 1 - pref[x - 1];
            // cout << one << " " << two << endl;
            if (two > one) {
                cout << one * 2 + 1;
            }
            else if (two == one) {
                cout << x;
            }
            else {
                if (one <= n - pref[n]) {
                    cout << (one * 2) + 1;
                }
                else {
                    cout << one + n - pref[n] + 1;
                }
            }
            cout << endl;
        }
    }
}

signed main() {
    int t = 1;
    while(t--) {
        solve();
    }
}
