#include <bits/stdc++.h>

using namespace std;

#define ll int
#define ld long double
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define pll pair<ll, ll>

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

const ll INF = SHRT_MAX;

ll a[1000100];


ll t[2000100];

ll n;

void upd(ll pos, ll x, ll v = 0, ll l = 1, ll r = n + 1) {
    if (l + 1 == r) {
        t[v] = (x == 1);
        return;
    }
    ll m = (l + r) / 2;
    if (pos < m) {
        upd(pos, x, v * 2 + 1, l, m);
    }
    else {
        upd(pos, x, v * 2 + 2, m, r);
    }
    t[v] = t[v * 2 + 1] + t[v * 2 + 2];
}

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

ll cnt[3];

void solve() {
    ll q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] > 1)
            a[i] = 2;
        cnt[a[i]]++;
        upd(i, a[i]);
    }
    bool fl = 1;
    while (q--) {
        ll t;
        cin >> t;
        if (t == 1) {
            ll ind;
            cin >> ind;
            swap(a[ind], a[ind + 1]);
            upd(ind, a[ind]);
            upd(ind + 1, a[ind + 1]);
        }
        else {
            ll x;
            cin >> x;
            if (a[x] == 1) {
                ll cn = get(1, x);
                ll par = min(cnt[1], cnt[2]);
                if (cn < par) {
                    cout << cn * 2 + 1 + (a[1] == 2) << '\n';
                }
                else {
                    cout << par * 2 + cn - par + 1 << '\n';
                }
            }
            else {
                ll cn = x - get(1, x) - 1;
                ll par = min(cnt[1], cnt[2]);
                if (cn < par) {
                    cout << cn * 2 + 1 << '\n';
                }
                else {
                    cout << par * 2 + cn - par + 1 << '\n';
                }
            }

        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
   // cin.tie(0);
    ll t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}
