#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

struct Bit {
    vector<int> t;
    Bit() = default;
    Bit(int n) : t(n + 1) {}
    int get(int l) {
        int res = 0;
        for (int i = l; i > 0; i -= i & -i) {
            res += t[i];
        }
        return res;
    }
    int get(int l, int r) {
        return get(r) - get(l);
    }
    void upd(int v, int x) {
        for (int i = v + 1; i < t.size(); i += i & -i) {
            t[i] += x;
        }
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    Bit one(n), two(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == 1) {
            one.upd(i, 1);
        } else {
            two.upd(i, 1);
        }
    }
    while (q-- > 0) {
        int tp;
        cin >> tp;
        if (tp == 1) {
            int x;
            cin >> x;
            --x;
            if (a[x] == a[x + 1]) continue;
            if (a[x] == 1) {
                one.upd(x, -1);
                one.upd(x + 1, 1);
                two.upd(x, 1);
                two.upd(x + 1, -1);
            } else {
                two.upd(x, -1);
                two.upd(x + 1, 1);
                one.upd(x, 1);
                one.upd(x + 1, -1);
            }
            swap(a[x], a[x + 1]);
        } else {
            int y;
            cin >> y;
            --y;
            if (a[y] == a[0]) {
                if (a[y] == 1) {
                    int x = one.get(y);
                    cout << x + min(two.get(n), x) + 1 << '\n';
                } else {
                    int x = two.get(y);
                    cout << x + min(one.get(n), x) + 1 << '\n';
                }
            } else {
                if (a[y] == 1) {
                    int x = one.get(y);
                    cout << x + min(x + 1, two.get(n)) + 1 << '\n';
                } else {
                    int x = two.get(y);
                    cout << x + min(x + 1, one.get(n)) + 1 << '\n';
                }
            }
        }
    }

    return 0;
}