#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll mod = 998244353;
const ll inf = 1e17;

void solve() {
    ll n, q; cin >> n >> q;
    vector<ll> A(n);
    for (ll i = 0; i < n; ++i) cin >> A[i];
    vector<ll> cnt1(n + 1, 0), cnt2(n + 1, 0);
    for (ll i = 0; i < n; ++i) {
        if (A[i] == 1) {
            cnt1[i + 1] = cnt1[i] + 1;
            cnt2[i + 1] = cnt2[i];
        } else {
            cnt1[i + 1] = cnt1[i];
            cnt2[i + 1] = cnt2[i] + 1;
        }
    }
    while (q--) {
        ll t; cin >> t;
        ll x; cin >> x;
        x--;
        if (t == 1) {
            if (A[x] != A[x + 1]) {
                if (A[x] == 1) {
                    cnt1[x + 1]--;
                    cnt2[x + 1]++;
                } else {
                    cnt1[x + 1]++;
                    cnt2[x + 1]--;
                }
            }
            ll val = A[x];
            A[x] = A[x + 1];
            A[x + 1] = val;
            continue;
        }
        if (A[x] == 1) {
            if (A[0] == 1) {
                ll ans = cnt1[x + 1];
                ans += min(cnt2[n], ans - 1);
                cout << ans << '\n';
                continue;
            }
            ll ans = cnt1[x + 1];
            ans += min(cnt2[n], ans);
            cout << ans << '\n';
            continue;
        }
        if (A[0] == 2) {
            ll ans = cnt2[x + 1];
            ans += min(cnt1[n], ans - 1);
            cout << ans << '\n';
            continue;
        }
        ll ans = cnt2[x + 1];
        ans += min(cnt1[n], ans);
        cout << ans << '\n';
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}