#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define all(a) a.begin(), a.end()

void solve();

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
#ifdef LOCAL
    cin >> t;
#else
#endif
    while (t--) solve();
}

const ll N = 1 << 19;
ll n, q;

struct Node {
    ll sz, pmn, sm, mn;

    Node() : sz(0), pmn(0), sm(0), mn(0) {
    }

    Node(ll x) : sm(x), sz(1) {
        if (x < 0) {
            mn = x;
            pmn = 1;
        } else {
            mn = 0;
            pmn = 0;
        }
    }

    Node operator+(const Node &oth) const {
        Node res;
        res.sm = sm + oth.sm;
        res.sz = sz + oth.sz;
        if (mn <= sm + oth.mn) {
            res.mn = mn;
            res.pmn = pmn;
        } else {
            res.mn = sm + oth.mn;
            res.pmn = sz + oth.pmn;
        }
        return res;
    }
} sg[N * 2]{};

void upd(ll i, ll d) {
    sg[N + i] = Node(d);
    for (ll v = (N + i) / 2; v > 0; v /= 2)
        sg[v] = sg[v * 2] + sg[v * 2 + 1];
}

Node get(ll lx, ll rx, ll v = 1, ll l = 0, ll r = N) {
    if (lx <= l && r <= rx) return sg[v];
    if (lx >= r || l >= rx) return Node();
    ll m = (l + r) / 2;
    return get(lx, rx, v * 2, l, m) + get(lx, rx, v * 2 + 1, m, r);
}

void solve() {
    cin >> n >> q;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
        if (a[i] == 0) upd(i, 1);
        else upd(i, -1);
    }
    for (ll i = 0; i < q; i++) {
        ll t, x;
        cin >> t >> x;
        x--;
        if (t == 1) {
            swap(a[x], a[x + 1]);
            upd(x, a[x]);
            upd(x + 1, a[x + 1]);
        } else {
            Node r = get(0, x + 1);
            if (r.pmn == x + 1) cout << x + 1 << "\n";
            else {
                if (a[x] > 0) cout << (x + 1) - (r.sm - r.mn);
                else {
                    ll res = (x + 1) + (r.sm - r.mn) - 1;
                    Node f = get(0, n);
                    if (f.pmn > r.pmn || res <= n - (f.sm - f.mn)) cout << res << "\n";
                    else cout << res + (res - (n - (f.sm - f.mn))) / 2 << "\n";
                }
            }
        }
    }
}
