#include<bits/stdc++.h>
#define all(p) p.begin(),p.end()
using namespace std;
#define int long long
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    int a[n + 1];
    int pref[n + 1];
    fill(pref, pref + n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pref[i] = pref[i - 1] + (a[i] - 1);
    }
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            cin >> x;
            swap(pref[x], pref[x + 1]);
            swap(a[x], a[x + 1]);
        } else {
            // for (int i = 1; i <= n; i++) {
            //     cout << a[i] << ' ';
            // }
            // cout << endl;
            int x;
            cin >> x;
            if (a[x] == 1) {
                if (a[1] == 1) {
                    if (x - pref[x] - 1 <= pref[n]) {
                        cout << 2 * (x - pref[x] - 1) + 1 << endl;
                    } else {
                        cout << 2 * pref[n] + (x - pref[x] - pref[n]) << endl;
                    }
                } else {
                    if (x - pref[x] - 1 <= pref[n]) {
                        cout << 2 * (x - pref[x]) << endl;
                    } else {
                        cout << 2 * pref[n] + (x - pref[x] - pref[n]) << endl;
                    }
                }
            } else {
                if (a[1] == 2) {
                    if (pref[x] - 1 <= n - pref[n]) {
                        cout << 2 * (pref[x] - 1) + 1 << endl;
                    } else {
                        cout << 2 * (n - pref[n]) + (pref[x] - (n - pref[n])) << endl;
                    }
                } else {
                    if (pref[x] - 1 <= n - pref[n]) {
                        cout << 2 * (pref[x]) << endl;
                    } else {
                        cout << 2 * (n - pref[n]) + (pref[x] - (n - pref[n])) << endl;
                    }
                }
            }
        }
    }
}