#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    vector<int> am1(n + 1, 0), am2(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == 1)
            am1[i + 1] = am1[i] + 1;
        else
            am1[i + 1] = am1[i];
        if (a[i] == 2)
            am2[i + 1] = am2[i] + 1;
        else
            am2[i + 1] = am2[i];
    }

    for (int i = 0; i < q; ++i) {
        int type;
        cin >> type;
        if (type == 1) {
            int x;
            cin >> x;
            if (a[x - 1] == a[x])
                continue;
            if (a[x - 1] == 1) {
                --am1[x];
                ++am2[x];
            } else {
                --am2[x];
                ++am1[x];
            }
            swap(a[x - 1], a[x]);
        } else {
            int x;
            cin >> x;
            if (x == 1) {
                cout << 1 << endl;
                continue;
            }
            --x;
            int val = a[x];
            if (val == 1) {
                if (am1[1] != 0)
                    cout << am1[x + 1] + min(am2.back(), am1[x + 1] - 1) << endl;
                else
                    cout << 1 + am1[x + 1] + min(am2.back() - 1, am1[x + 1] - 1) << endl;
            } else {
                if (am2[1] != 0)
                    cout << am2[x + 1] + min(am1.back(), am2[x + 1] - 1) << endl;
                else
                    cout << 1 + am2[x + 1] + min(am1.back() - 1, am2[x + 1] - 1) << endl;
            }
        }
    }
}
