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