#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<int> a;
int n, q;

signed main(){
    cin >> n >> q;
    a.resize(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<int> pref(n + 1);
    for(int i= 0; i < n; i++){
        pref[i + 1] = pref[i];
        if(a[i] == 1){
            pref[i + 1]++;
        }
    }
    while(q--){
        int op;
        cin >> op;
        if(op == 1){
            int x;
            cin >> x;
            x--;
            if(a[x] == 1 && a[x + 1] == 2){
                pref[x + 1]--;
            }else if(a[x] == 2 && a[x + 1] == 1){
                pref[x + 1]++;
            }
            swap(a[x], a[x + 1]);
        }else{
            int x;
            cin >> x;
            x--;
            if(a[x] == 1){
                if(a[0] == 1){
                    cout << 2 * pref[x + 1] - 1 << endl;
                }else{
                    cout << 2 * pref[x + 1] << endl;
                }
            }else{
                int z = x + 1 - pref[x + 1];
                if(a[0] == 2){
                    cout << 2 * z - 1 << endl;
                }else{
                    cout << 2 * z << endl;
                }
            }
        }
    }
}
