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

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++){
        if (arr[i] == 1){
            cnt[min(1, arr[i])].insert(i);
        } else {
            cnt[min(1, arr[i])].insert(i);
        }
    }
    while (q--){
        int t;
        cin >> t;
        if (t == 1){
            int x;
            cin >> x;
            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);
                cout << tmp + idx + min((int) cnt[1].size() - tmp, idx) + 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;
                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;
}
