#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
// #define int long long


const int N = 5e5 + 10;
int a[N];
int cnt[N];
int n, q;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        cnt[i] = cnt[i - 1];
        if (a[i] == 1) {
            cnt[i]++;
        }
    }
    while (q--) {
        int type, x;
        cin >> type >> x;
        if (type == 1) {
            if (a[x] == 1 && a[x + 1] != 1) {
                cnt[x]--;
                cnt[x + 1]++;
            } else if (a[x] != 1 && a[x + 1] == 1) {
                cnt[x]++;
            }
            swap(a[x], a[x + 1]);
        } else {
            int i = cnt[x];
            int j = x - cnt[x];
            int ii = cnt[n] - cnt[x];
            int jj = (n - x) - ii;
            if (a[x] != 1) {
                swap(i, j);
                swap(ii, jj);
            }
            if (i <= j) {
                if (a[1] == a[x]) {
                    cout << 2 * i - 1 << "\n";
                } else {
                    cout << 2 * i << "\n";
                }
            } else {
                if (a[1] == a[x]) {
                    cout << 2 * j + 1 + i - j - 1 + min(i - j - 1, jj) << "\n";
                } else {
                    cout << 2 * j + i - j + min(i - j, jj) << "\n";
                }
            }
        }
    }
    return 0;
}
