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

// using namespace __gnu_pbds;
// template<class T> 
// using ordered_set = <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
using ld = long double;

#define int long long

struct Segtree {
    int n;
    vector<int> tree;
    Segtree(int n) : n(n) {
        tree.assign(2 * n, 0);
    }
    void upd(int i, int x) {
        i += n;
        tree[i] += x;
        i >>= 1;
        while (i) {
            tree[i] = tree[i << 1] + tree[i << 1 | 1];
            i >>= 1;
        }
    }

    int get(int l, int r) {
        if (l >= r) {
            return 0;
        }
        l += n;
        r += n;
        int res = 0;
        while (l != r) {
            if (l & 1) {
                res += tree[l++];
            }
            if (r & 1) {
                res += tree[--r];
            }
            l >>= 1;
            r >>= 1;
        }
        return res;
    }
};

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i =0 ; i < n; ++i) {
        cin >> a[i];
    }

    Segtree tree(n);
    vector<int> c(n + 1);
    for (int i = 0; i < n; ++i) {
        c[a[i]]++;
        if (a[i] == 1) {
            tree.upd(i, 1);
        }
    }

    for (int i = 0; i < q; ++i) {
        int type;
        cin >> type;
        if (type == 1) {
            int x;
            cin >> x;
            if (a[x - 1] == 1 && a[x] == 2) {
                tree.upd(x - 1, -1);
                tree.upd(x, 1);
            }
            if (a[x] == 1 && a[x - 1] == 2) {
                tree.upd(x - 1, 1);
                tree.upd(x, -1);
            }
            swap(a[x - 1], a[x]);
        } else {
            int x;
            cin >> x;
            x--;
            if (a[x] == 1) {
                int le = tree.get(0, x);
                if (le < c[2]) {
                    cout << 2 * le + (a[0] != 1) + 1 << '\n';
                } else if (le == c[2]) {
                    cout << 2 * le + 1 << '\n';
                } else {
                    cout << c[2] + le + 1 << '\n';
                }
            } else {
                int le = x - tree.get(0, x);
                if (le < c[1]) {
                    cout << 2 * le + (a[0] != 2) + 1 << '\n';
                } else if (le == c[1]) {
                    cout << 2 * le + 1 << '\n';
                } else {
                    cout << c[1] + le + 1 << '\n';
                }
            }
        }
    }
}

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

    #ifdef LOCAL
    freopen("C:\\Users\\User\\Documents\\olymp\\input.txt", "r", stdin);
    freopen("C:\\Users\\User\\Documents\\olymp\\output.txt", "w", stdout);
    #endif

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}