#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define ff first
#define ss second

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> cnt1{0}, cnt2{0};
    for (int i = 0; i < n; i++) {
        cnt1.push_back(cnt1.back());
        if (a[i] == 1) cnt1.back() += 1;
        cnt2.push_back(cnt2.back());
        if (a[i] == 2) cnt2.back() += 1;
    }
    for (int i = 0; i < q; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            int v;
            cin >> v;
            swap(a[v - 1], a[v]);
            if (a[v - 1] == a[v]) continue;
            else {
                if (a[v - 1] == 1) cnt1[v]--, cnt2[v]++;
                else cnt2[v]--, cnt1[v]++;
            }

        } else {
            int v;
            cin >> v;
            if (a[0] == 1) {
                if (a[v - 1] == 2) {
                    cout << min(cnt2[v], cnt1.back()) + cnt2[v] << "\n";
                } else {
                    cout << min(cnt1[v], cnt2.back()) + cnt1[v] - 1 << "\n";
                }
            } else {
                if (a[v - 1] == 2) {
                    cout << min(cnt2[v], cnt1.back()) + cnt2[v] - 1 << "\n";
                } else cout << min(cnt1[v], cnt2.back()) + cnt1[v] << "\n";
            }
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//    cin >> t;
    while (t--) solve();
}
