#include <bits/stdc++.h>
#define int long long

using namespace std;

vector <int> tree;
vector <int> arr;

void build(int v, int l, int r) {
    if (l == r - 1) {
        tree[v] = arr[l];
        return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m);
    build(2 * v + 1, m, r);
    tree[v] = tree[2 * v] + tree[2 * v + 1];
}

void upd(int v, int l, int r, int pos, int x) {
    if (l == r - 1) {
        tree[v] = x;
        return;
    }
    int m = (l + r) / 2;
    if (l < m) upd(2 * v, l, m, pos, x);
    else upd(2 * v + 1, m, r, pos, x);
    tree[v] = tree[2 * v] + tree[2 * v + 1];
}

int get(int v, int l, int r, int tl, int tr) {
    if (tl >= r || l >= tr) return 0;
    if (tl <= l && r <= tr) return tree[v];
    int m = (l + r) / 2;
    return get(2 * v, l, m, tl, tr) + get(2 * v + 1, m, r, tl, tr);
}

signed main() {
    int n, q;
    cin >> n >> q;
    arr.resize(n);
    tree.resize(4 * n);
    int all1 = 0, all0 = 0;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        arr[i]--;
        all1 += arr[i];
        all0 += !arr[i];
    }
    build(1, 0, n);
    while (q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            x--;
            swap(arr[x], arr[x + 1]);
            upd(1, 0, n, x, arr[x]);
            upd(1, 0, n, x + 1, arr[x + 1]);
        } else {
            x--;
            int c1 = get(1, 0, n, 0, x);
            int c0 = x - c1;
            if (x == 0) {
                cout << 1 << endl;
                continue;
            }
            if (arr[x]) {
                if (arr[0]) {
                    cout << c1 + min(c1, all0) + 1 << endl;
                } else {
                    cout << c1 + min(all0, c1 + 1) + 1 << endl;
                }
            } else {
                if (!arr[0]) {
                    cout << c0 + min(c0, all1) + 1 << endl;
                } else {
                    cout << c0 + min(all1, c0 + 1) + 1 << endl;
                }
            }
        }
    }
    return 0;
}
