#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;


int main(){
    int n,q;
    cin >> n >> q;
    vector<int> c(n + 1);
    for(int i = 1;i <= n;i++){
        cin >> c[i];
    }
    vector<int> p(n + 1);
    for(int i = 1;i <= n;i++){
        if(c[i] == 1){
            p[i] = 1;
        }
        p[i] += p[i-1];
    }
    //int q;
    //cin >> q;
    while(q--){
        int t;
        cin >> t;
        if(t == 1){
            int x;
            cin >> x;
            //x--;
            if(c[x] == c[x + 1]){
                continue;
            }
            if(c[x] == 1){
                p[x]--;
            }else if(c[x + 1] == 1){
                p[x]++;
            }
            swap(c[x],c[x + 1]);
        }else{
            int y;
            cin >> y;
            vector<int> ans(n + 1);
            vector<bool> used(n + 1);
            int val = 0;
            int ind = 0,ind1 = -1,prev = -1;
            while(ind <= n){
                if(used[ind]){
                    ind++;
                    continue;
                }
                if(ind == ind1){
                    ind1 = -1;
                }
                if(c[ind] != prev){
                    ans[ind] = val++;

                    prev = c[ind];
                    ind1 = -1;
                    ind++;
                }else{
                    if(ind1 == -1){
                        ind1 = n + 1;
                        for(int i = ind + 1;i <= n;i++){
                            if(!used[i] and c[i] != c[ind]){
                                ind1 = i;
                                break;
                            }
                        }
                    }
                    if(ind1 == n + 1){
                        ans[ind] = val++;
                        ind++;
                        continue;
                    }
                    ans[ind1] = val++;
                    prev = c[ind1];
                    used[ind1] = 1;
                    ind1 = -1;
                }
            }
            cout << ans[y] << "\n";
        }
    }
    return 0;
}
