#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ld = long double;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (auto &el : a) cin >> el;
    vector<int> b, c;
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            b.pb(i);
        } else c.pb(i);
    }
    for (int i = 0; i < q; i++) {
        int t, j;
        cin >> t >> j;
        j--;
        if (t == 1) {
            if (a[j] != a[j + 1]) {
                int bi = lower_bound(all(b), j) - b.begin();
                int ci = lower_bound(all(c), j) - c.begin();
                swap(b[bi], c[ci]);
            }
        } else {
            if (a[j] == 2) swap(b, c);
            int bi = lower_bound(all(b), j) - b.begin() + 1;
            if (bi > c.size()) {
                cout << c.size() + bi << "\n";
            } else {
                if (a[0] == a[j]) {
                    cout << bi * 2 - 1 << "\n";
                } else {
                    cout << bi * 2 << "\n";
                }
            }
            if (a[j] == 2) swap(b, c);
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) solve();
}
