// #pragma GCC optimize("O3")

#include <iostream>
#include <vector>
#include <set>

using namespace std;
using ll = long long;

struct SegTree {
    vector<int> tree;
    void build(int p, int l, int r, vector<int>& a) {
        if (r - l == 1) {
            tree[p] = a[l];
            return;
        }
        int m = (l + r) / 2;
        build(2 * p + 1, l, m, a);
        build(2 * p + 2, m, r, a);
        tree[p] = tree[2 * p + 1] + tree[2 * p + 2];
    }
    void update(int p, int l, int r, int i, int x) {
        if (r - l == 1) {
            tree[p] = x;
            return;
        }
        int m = (l + r) / 2;
        if (i < m) {
            update(2 * p + 1, l, m, i, x);
        } else {
            update(2 * p + 2, m, r, i, x);
        }
        tree[p] = tree[2 * p + 1] + tree[2 * p + 2];
    }
    int get(int p, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) return tree[p];
        if (l >= qr || r <= ql) return 0;
        int m = (l + r) / 2;
        return get(2 * p + 1, l, m, ql, qr) + get(2 * p + 2, m, r, ql, qr);
    }
    SegTree(vector<int>& a) {
        tree.resize(4 * a.size());
        build(0, 0, a.size(), a);
    }
};

int main() {
    #ifdef LOCAL
    freopen("_test.in", "r", stdin);
    freopen("_test.out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];

    int one_q = 0;
    int two_q = 0;

    vector<int> is_one(n + 1);
    for (int i = 1; i <= n; i++) {
        if (a[i] == 1) {
            is_one[i] = 1;
            one_q++;
        } else {
            two_q++;
        }
    }

    SegTree tree(is_one);

    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            cin >> x;

            int a = tree.get(0, 0, n + 1, x, x + 1);
            int b = tree.get(0, 0, n + 1, x + 1, x + 2);

            tree.update(0, 0, n + 1, x, b);
            tree.update(0, 0, n + 1, x + 1, a);
        } else {
            int y;
            cin >> y;

            int start = tree.get(0, 0, n + 1, 1, 2);
            int cur = tree.get(0, 0, n + 1, y, y + 1);

            if (start == cur && cur == 1) {
                int left = tree.get(0, 0, n + 1, 1, y);
                if (left <= two_q) {
                    cout << left * 2 + 1 << '\n';
                } else {
                    cout << two_q + left + 1;
                }
            } else if (start == cur && cur == 0) {
                int left = y - 1 - tree.get(0, 0, n + 1, 1, y);
                if (left <= one_q) {
                    cout << left * 2 + 1 << '\n';
                } else {
                    cout << one_q + left + 1;
                }
            } else if (start != cur && cur == 1) {
                int left = tree.get(0, 0, n + 1, 1, y);
                if (left <= two_q) {
                    cout << 2 * left + 1  << '\n';
                } else {
                    cout << two_q + left + 1 << '\n';
                }
            } else {
                int left = y - 1 - tree.get(0, 0, n + 1, 1, y);
                if (left <= one_q) {
                    cout << 2 * left + 1 << '\n';
                } else {
                    cout << one_q + left + 1 << '\n';
                }
            }
        }
    }
}