#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

#define int long long
#define all(x) x.begin(), x.end()

const int inf = 1e18;
const int mod = 998244353;

template<typename T>
using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

struct segTree {
    vector<int> t;
    int n;

    segTree(vector<int>& a) {
        n = a.size();
        t.assign(2 * n, 0);
        for (int i = 0; i < n; i++) t[i + n] = a[i];
        for (int i = n - 1; i >= 0; i--) t[i] = max(t[i << 1], t[(i << 1) | 1]);
    }

    int get(int l, int r) {
        int ans = -inf;
        l += n, r += n;
        while (l < r) {
            if (l & 1) ans = max(ans, t[l++]);
            if (r & 1) ans = max(ans, t[--r]);
            l >>= 1, r >>= 1;
        }
        return ans;
    }

    void upd(int i, int x) {
        i += n, t[i] = x, i >>= 1;
        while (i) t[i] = max(t[i << 1], t[(i << 1) | 1]), i >>= 1;
    }
};

struct Fen {
    vector<int> t;
    int n;

    Fen(int x) {n = x;t.assign(n + 1, 0);}
    int sum(int r) {int ans = 0;for (; r > 0; r -= r & -r) ans += t[r];return ans;}
    int get(int l, int r) {l++, r++;return sum(r) - sum(l - 1);}
    void upd(int i, int x) {i++;for (; i <= n; i += i & -i) t[i] += x;}
};

void solve() {
    int n, q;
    cin >> n >> q;

    vector<int> a(n);
    for (int& i : a) cin >> i;

    Fen st1(n), st2(n);
    for (int i = 0; i < n; i++) {
        int x = a[i];
        if (x == 1) st1.upd(i, 1);
        else st2.upd(i, 1);
    }

    int cnt1 = 0;
    int cnt2 = 0;
    for (int& i : a) {
        if (i == 1) cnt1++;
        else cnt2++;
    }

    while (q--) {
        int t;
        cin >> t;

        if (t == 1) {
            int x;
            cin >> x;
            x--;

            if (a[x] == 1) st1.upd(x, -1);
            else st2.upd(x, -1);

            if (a[x + 1] == 1) st1.upd(x + 1, -1);
            else st2.upd(x + 1, -1);

            swap(a[x], a[x + 1]);

            if (a[x] == 1) st1.upd(x, 1);
            else st2.upd(x, 1);

            if (a[x + 1] == 1) st1.upd(x + 1, 1);
            else st2.upd(x + 1, 1);
        } else {
            int x;
            cin >> x;
            x--;
            if (x == 0) {
                cout << "1\n";
                continue;
            }
            int sm1 = st1.get(0, x);
            int sm2 = st2.get(0, x);

            if (a[x] == 1) {
                if (a[0] == 1) {
                    if (sm1 > cnt2) {
                        cout << sm1 + cnt2 << "\n";
                    } else {
                        cout << 2 * sm1 - 1 << "\n";
                    }
                } else {
                    if (sm2 >= cnt1) {
                        cout << cnt1 + sm2 << "\n";
                    } else {
                        cout << 2 * sm2 << "\n";
                    }
                }
            } else {
                if (a[0] == 1) {
                    if (sm2 >= cnt1) {
                        cout << cnt1 + sm2 << "\n";
                    } else {
                        cout << 2 * sm2 << "\n";
                    }
                } else {
                    if (sm2 > cnt1) {
                        cout << sm2 + cnt1 << "\n";
                    } else {
                        cout << 2 * sm2 - 1 << "\n";
                    }
                }
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif

    int t = 1;
    // cin >> t;

    while (t--) solve();
}