#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;

ll check(vector<ll> &a, ll x) {
    ll last = -1;
    vector<bool> used(a.size(), 0);
    ll cnt = 0;
    while (true) {
        bool k = 1;
        for (ll j = 0; j < a.size(); j++) {
            if (!used[j] && a[j] != last) {
                cnt++;
                used[j] = 1;
                last = a[j];
                if (j == x) {
                    return cnt;
                }
                k = 0;
                break;
            }
        }
        if (k == 1) break;
    }
    for (ll j = 0; j < a.size(); j++) {
        if (!used[j]) {
            cnt++;
            used[j] = 1;
            if (j == x) {
                return cnt;
            }
        }
    }
}

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, 0), cnt2(n, 0);
    if (a[0] == 1) cnt1[0] = 1;
    if (a[0] == 2) cnt2[0] = 2;
    for (ll i = 1; i < n; i++) {
        cnt1[i] = cnt1[i - 1], cnt2[i] = cnt2[i - 1];
        if (a[i] == 1) cnt1[i]++;
        if (a[i] == 2) cnt2[i]++;
    }
    ll c1 = cnt1.back(), c2 = cnt2.back();
    while (q--) {
        ll t;
        cin >> t;
        if (t == 1) {
            ll x;
            cin >> x;
            x--;
            if (a[x] == a[x + 1]) continue;
            if (a[x] == 1) {
                cnt1[x]--, cnt2[x]++;
            } else {
                cnt2[x]--, cnt1[x]++;
            }
        } else {
            ll y;
            cin >> y;
            y--;
            ll ans = 0;
            if (a[y] == 1) {
                if (cnt1[y] > c2) {
                    ans = 2 * c2 + (cnt1[y] - c2);
                } else {
                    if (a[0] == 1) ans = (cnt1[y] - 1) * 2 + 1;
                    else ans = (cnt1[y]) * 2;
                }
            } else {
                if (cnt2[y] > c1) {
                    ans = 2 * c1 + (cnt2[y] - c1);
                } else {
                    if (a[0] == 2) ans = (cnt2[y] - 1) * 2 + 1;
                    else ans = (cnt2[y]) * 2;
                }
            }
            cout << ans << '\n';
        }
    }
}

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