#include<bits/stdc++.h>
#define ll long long
#define ld long double

using namespace std;

ll n, q;
vector<ll> a;
vector<pair<ll, ll>> b;

void input() {
    cin >> n >> q;
    a.resize(n);
    b.resize(q);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (ll i = 0; i < q; i++) {
        cin >> b[i].first >> b[i].second;
    }
}

void solve() {
    vector<ll> num(n, 0);
    ll cnt1 = 0, cnt2 = 0;
    for (ll i = 0; i < n; i++) {
        if (a[i] == 1) {
            cnt1++;
            num[i] = cnt1;
        } else {
            cnt2++;
            num[i] = cnt2;
        }
    }
    for (ll i = 0; i < q; i++) {
        if (b[i].first == 1) {
            if (a[b[i].second - 1] == a[b[i].second]) {
                continue;
            }
            swap(a[b[i].second - 1], a[b[i].second]);
            swap(num[b[i].second - 1], num[b[i].second]);
        } else {
            ll ind = b[i].second - 1, coth;
            if (a[ind] == 1) {
                coth = cnt2;
            } else {
                coth = cnt1;
            }
            if (a[0] == a[ind]) {
                if (coth >= num[ind] - 1) {
                    cout << num[ind] * 2 + 1 << "\n";
                } else {
                    cout << num[ind] + coth << "\n";
                }
            } else {
                if (coth >= num[ind]) {
                    cout << num[ind] * 2 << "\n";
                } else {
                    cout << num[ind] + coth << "\n";
                }
            }
        }
    }
}

void output() {

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    input();
    solve();
    output();
    return 0;
}
