#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <experimental/random>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
using str = string;
using ld = long double;
const ll INF = 1e18, MOD = 998244353;
#define int long long
const int N = 600;
int c[N][N];
int binp(int v,int x) {
    if (x == 0) {
        return 1;
    }
    auto w = binp(v, x / 2);
    if (x % 2) {
        return w * w % MOD * v % MOD;
    }
    return w * w % MOD;
}

void solve();

signed main() {
    c[0][0] = 1;
    for (int i = 1; i < N; ++i) {
        for (int j = 0; j <= i; ++j) {
            if (j > 0) {
                c[i][j] += c[i - 1][j - 1];
            }
            if (j != i) {
                c[i][j] += c[i - 1][j];
            }
            c[i][j] %= MOD;
        }
    }
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--) {
        solve();
        //cout << "\n";
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    ordered_set t1, t2;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == 1) {
            t1.insert(i);
        } else {
            t2.insert(i);
        }
    }
    for (int i = 0; i < q; ++i) {
        int t, p;
        cin >> t >> p;
        if (t == 1) {
            p--;
            if (a[p] != a[p + 1]) {
                if (a[p] == 1) {
                    t1.erase(p);
                    t2.insert(p);
                    t2.erase(p + 1);
                    t1.insert(p + 1);
                } else {
                    t2.erase(p);
                    t1.insert(p);
                    t1.erase(p + 1);
                    t2.insert(p + 1);
                }
                swap(a[p], a[p + 1]);
            }
        } else {
            p--;
            if (a[p] == a[0]) {
                if (a[p] == 1) {
                    int k = t1.order_of_key(p + 1);
                    if (k > t2.size()) {
                        cout << t2.size() + k;
                    } else {
                        cout << 2 * k - 1;
                    }
                } else {
                    int k = t2.order_of_key(p + 1);
                    if (k > t1.size()) {
                        cout << t1.size() + k;
                    } else {
                        cout << 2 * k - 1;
                    }
                }
            } else {
                if (a[p] == 1) {
                    int k = t1.order_of_key(p + 1);
                    if (k >= t2.size()) {
                        cout << t2.size() + k;
                    } else {
                        cout << 2 * k;
                    }
                } else {
                    int k = t2.order_of_key(p + 1);
                    if (k >= t1.size()) {
                        cout << t1.size() + k;
                    } else {
                        cout << 2 * k;
                    }
                }
            }
            cout << "\n";
        }
    }
}
