#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";
    }
}

struct seg_tree {
    vector<pair<int,int> > t;

    seg_tree(int n) {
        t.resize(4 * n + 5);
    }

    void add(int v,int l,int r,int p,int x) {
        if (r - l == 1) {
            t[v] = {x, max(0ll, x)};
            return;
        }
        int m = (l + r) / 2;
        if (p < m) {
            add(2 * v, l, m, p, x);
        } else {
            add(2 * v + 1, m, r, p, x);
        }
        t[v].first = t[2 * v].first + t[2 * v + 1].first;
        t[v].second = max(t[2 * v].second, t[2 * v].first + t[2 * v + 1].second);
    }

    pair<int,int> get(int v,int l,int r,int ql,int qr) {
        if (l == ql && qr == r) {
            return t[v];
        }
        int qm = (ql + qr) / 2;
        if (r <= qm) {
            return get(2 * v, l, r, ql, qm);
        } else if (l >= qm) {
            return get(2 * v + 1, l, r, qm, qr);
        }
        auto k = get(2 * v, l, qm, ql, qm);
        auto k1 = get(2 * v + 1, qm, r, qm, qr);
        return {k.first + k1.first, max(k.second, k.first + k1.second)};
    }
};

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    seg_tree t(n);
    int cnt2 = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] > 1) {
            cnt2++;
            t.add(1, 0, n, i, 1);
        } else {
            t.add(1, 0, n, i, -1);
        }
    }
    for (int i = 0; i < q; ++i) {
        int T, p;
        cin >> T >> p;
        if (T == 1) {
            p--;
            if (a[p] != a[p + 1]) {
                swap(a[p], a[p + 1]);
                if (a[p] > 1) {
                    t.add(1, 0, n, p, 1);
                } else {
                    t.add(1, 0, n, p, -1);
                }
                if (a[p + 1] > 1) {
                    t.add(1, 0, n, p + 1, 1);
                } else {
                    t.add(1, 0, n, p + 1, -1);
                }
            }
        } else {
            auto f = t.get(1, 0, p, 0, n);
            if (a[p - 1] == 1) {
                int c2 = (p + f.first) / 2;
                int c1 = c2 - f.first;
                cout << f.second + 2 * (c2 - f.second) << "\n";
            } else {
                int c2 = (p + f.first) / 2;
                int c1 = c2 - f.first;
                cout << min(cnt2 + c1, 2 * f.first - 1+f.second) << "\n";
            }
        }
    }
}
