#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

mt19937 rng(52);

ll get(ll l, ll r) {
    ll x = rng() % (r-l+1);
    return x + l;
}


void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> v(n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (v[i] != 1) cnt++;
    }
    vector<int> pref(n, 0);
    for (int i = 1; i < n; i++) {
        pref[i] = pref[i-1] + (v[i-1] == 1);
    }
    for (int i = 0; i < q; i++) {
        int t, x;
        cin >> t >> x;
        x--;
        if (t == 1) {
            if (v[x] == v[x+1]) continue;
            if (v[x] != 1) {
                pref[x+1]++;
            } else {
                pref[x+1]--;
            }
            swap(v[x], v[x+1]);
        } else {
            if (v[x] != 1) {
                cout << (x - pref[x] + 1) + min(pref[x], (x - pref[x] + 1)) << '\n';
            } else {
                if (x - pref[x] > pref[x]) {
                    cout << x+1 << '\n';
                } else {
                    cout << min(pref[x], cnt) + pref[x] + 1 << '\n';
                }
            }
        }
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll t = 1;
    //cin >> t;
    while(t--) solve();

    return 0;
}

