#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cassert>
#include <random>
#define rep(n) for (int (i) = 0; (i) < (n); (i)++)
#define all(n) (n).begin(), (n).end()
#define rall(n) (n).rbegin(), (n).rend()
#define mp make_pair
#define ll long long
#define ld long double
//#define int long long
//#define FILE
//#define DEBUG

using namespace std;

const int mod = 998244353;
const ll inf = 4e18;

void solve() {
    int n, q; cin >> n >> q;
    vector<int> A(n);
    vector<int> set1, set2;
    rep(n) {
        cin >> A[i];
        if (A[i] == 1)
            set1.push_back(i);
        else
            set2.push_back(i);
    }
    while (q--) {
        int ty;
        cin >> ty;
        if (ty == 1) {
            int idx; cin >> idx; idx--;
            if (A[idx] != A[idx + 1]) {
                if (A[idx] == 1)
                    set1[lower_bound(all(set1), idx) - set1.begin()]++;
                else
                    set2[lower_bound(all(set2), idx) - set1.begin()]++;
                    

                if (A[idx + 1] == 1)
                    set1[lower_bound(all(set1), idx + 1) - set1.begin()]--;
                else
                    set2[lower_bound(all(set2), idx + 1) - set1.begin()]--;
                
                swap(A[idx], A[idx + 1]);
            }
        }
        else {
            int idx; cin >> idx; idx--;
            int flag = 1;
            if (A[idx] == 2) {
                swap(set1, set2);
                flag = 2;
            }
            int pos = lower_bound(all(set1), idx) - set1.begin();
            int ans = pos + 1;
            ans += min<int>(pos, set2.size()  + (A[0] != flag));
            cout << ans << endl;
        }
    }
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "W", stdout);
#endif
#ifndef DEBUG
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
#else
    int tt = 1;
    cin >> tt;
    int cnt = 1;
    while (tt--) {
        n = rand() % 3 + 1;
        A.resize(n);
        rep(n) {
            A[i].first = (ll) rand() % 10 - 5;
            A[i].second = (ll) rand() % 10 - 5;
        }
        ll ans1 = solve();
        ll ans2 = solve2();
        assert(ans1 == ans2);
        A.clear();
        cout << cnt++ << endl;
    }
#endif
}
/*
4
-6 -1
-5 14
0 10
-30 2
-1 -1 -1 -1


*/