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

//#define int long long
#define all(arr) arr.begin(), arr.end()
#define rall(arr) arr.rbegin(), arr.rend()

typedef long long ll;
typedef long double ld;
typedef __int128 lll;

mt19937_64 rnd(0);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

struct node{
    int suff_max = 0, is_all = 1, sz = 0;
};

struct seg_tree{
    int size = 1;
    vector<node> tree;

    void init(int n){
        while (size < n) size *= 2;
        tree.resize(2 * size - 1);
    }

    node nw(node a, node b){
        node c;
        c.is_all = 0;
        c.suff_max = b.suff_max;
        if (b.is_all){
            c.suff_max += a.suff_max;
            if (a.is_all){
                c.is_all = 1;
            }
        }
        c.sz = a.sz + b.sz;
        return c;
    }

    void build(vector<int>& arr, int x, int lx, int rx){
        if (rx - lx == 1){
            if (lx < (int) arr.size()){
                if (arr[lx] == 0){
                    tree[x].suff_max = tree[x].is_all = tree[x].sz = 1;
                } else {
                    tree[x].sz = 1;
                    tree[x].is_all = 0;
                }
            }
            return;
        }
        int m = (lx + rx) / 2;
        build(arr, 2 * x + 1, lx, m);
        build(arr, 2 * x + 2, m, rx);
        tree[x] = nw(tree[2 * x + 1], tree[2 * x + 2]);
    }

    void build(vector<int>& arr){
        init(arr.size());
        build(arr, 0, 0, size);
    }

    void set(int i, int v, int x, int lx, int rx){
        if (rx - lx == 1){
            if (v == 0){
                tree[x].suff_max = tree[x].is_all = 1;
            } else {
                tree[x].suff_max = tree[x].is_all = 0;
            }
            return;
        }
        int m = (lx + rx) / 2;
        if (i < m){
            set(i, v, 2 * x + 1, lx, m);
        } else {
            set(i, v, 2 * x + 2, m, rx);
        }
        tree[x] = nw(tree[2 * x + 1], tree[2 * x + 2]);
    }

    void set(int i, int v){
        set(i, v, 0, 0, size);
    }

    node get_suf(int i, int x, int lx, int rx){
        if (i <= lx){
            return node();
        }
        if (i >= rx){
            return tree[x];
        }
        int m = (lx + rx) / 2;
        return nw(get_suf(i, 2 * x + 1, lx, m), get_suf(i, 2 * x + 2, m, rx));
    }

    int get_ans(int r){
        return get_suf(r, 0, 0, size).suff_max;
    }
};

void solve(){
    int n, q;
    cin >> n >> q;
    vector<int> arr(n);
    for (int i = 0; i < n; i++){
        cin >> arr[i];
        arr[i]--;
    }
    vector<ordered_set> cnt(2);
    for (int i = 0; i < n; i++){
        cnt[min(1, arr[i])].insert(i);
    }
    seg_tree st;
    st.build(arr);
    while (q--){
        int t;
        cin >> t;
        if (t == 1){
            int x;
            cin >> x;
            x--;
            st.set(x, arr[x + 1]);
            st.set(x + 1, arr[x]);
            cnt[min(arr[x], 1)].erase(x);
            cnt[min(1, arr[x + 1])].erase(x + 1);
            swap(arr[x], arr[x + 1]);
            cnt[min(arr[x], 1)].insert(x);
            cnt[min(arr[x + 1], 1)].insert(x + 1);
        } else {
            int y;
            cin >> y;
            y--;
            if (arr[y] == 0){
                int tmp = cnt[1].order_of_key((*cnt[0].begin()));
                int idx = cnt[0].order_of_key(y);
                int kk = cnt[1].order_of_key(y) - tmp;
                if ((int) cnt[1].size() - tmp < idx){
                    cout << cnt[1].size() + idx + 1 << '\n';
                    continue;
                }
                cout << y + st.get_ans(y + 1) << '\n';
            } else {
                int tmp = cnt[1].order_of_key((*cnt[0].begin()));
                int cnt_1 = cnt[0].order_of_key(y);
                int kk = cnt[1].order_of_key(y) - tmp;
                if (cnt_1 == 0){
                    cout << y + 1 << '\n';
                    continue;
                }
                cout << tmp + 1 + cnt_1 + kk - max(0, cnt_1 - kk - 1) << '\n';
            }
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(10);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--){
        solve();
        cout << '\n';
    }
    return 0;
}
