#include <bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2,popcnt")
#pragma GCC target("tune=native")

using namespace std;

#define int long long
#define sz(x) (int)x.size()
#define eb emplace_back
#define vi vector<int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vvi vector<vi>
#define vpi vector<pair<int, int> >
#define pi pair<int, int>
#define vvvi vector<vvi>

void solve_a() {
    int n, q; cin >> n >> q;
    vi a(n);
    set<int> st;
    for (int &x : a) {
        cin >> x;
        st.insert(x);
    }
    vi b(all(st));
    for (int &x : a) x = lower_bound(all(b), x) - b.begin();
    vpi v(n);
    int c1 = 0, c2 = 0;
    for (int i = 0; i < n; ++i) {
        v[i] = {c1, c2};
        if (a[i] == 0) c1++;
        else c2++;
    }
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int x; cin >> x;
            if (a[x - 1] == 0) v[x].fi--;
            else v[x].se--;
            if (a[x] == 0) v[x - 1].fi++;
            else v[x - 1].se++;
            swap(a[x], a[x - 1]);
            swap(v[x], v[x - 1]);
        } else {
            int x; cin >> x;
            --x;
            if (v[x].fi >= c2 && a[x] == 0) cout << v[x].fi + c2 + 1 << endl;
            else if (v[x].se >= c1 && a[x] != 0) cout << v[x].se + c1 + 1 << endl;
            else {
                if (a[0] == a[x]) {
                    if (a[x] == 0) cout << 2 * v[x].fi + 1 << endl;
                    else cout << 2 * v[x].se + 1 << endl;
                } else {
                    if (a[x] == 0) cout << 2 * v[x].fi + 2 << endl;
                    else cout << 2 * v[x].se + 2 << endl;
                }
            }
        }
    }
}

void solve_c() {

}

signed main() {
   //freopen("C:/work/untitled1/input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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