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

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update<>>

const int MOD = 998244353;
const int INF = 1e18;


void solve() {
    int n, q;
    cin >> n >> q;

    vector<int> a(n, 0);

    vector<vector<int> > dt(2);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
        dt[a[i]].push_back(i);
    }


    while (q--) {
        int t;
        cin >> t;

        if (t == 1) {
            int x;
            cin >> x;
            x--;
            if (a[x] == a[x + 1]) {
                continue;
            }
            int c1 = a[x];
            int c2 = a[x + 1];
            swap(a[x], a[x + 1]);
            int id1 = lower_bound(all(dt[c1]), x) - dt[c1].begin();
            int id2 = lower_bound(all(dt[c2]), x + 1) - dt[c2].begin();
            dt[c1][id1] = x + 1;
            dt[c2][id2] = x;
        } else {
            int y;
            cin >> y;
            y--;
            int c = a[y];
            int id = lower_bound(all(dt[c]), y) - dt[c].begin();
            if (dt[1 - c].size() == 0) {
                cout << id + 1 << endl;
                continue;
            }
            int ans = 0;
            if (dt[c][0] > dt[1 - c][0]) {
                ans = id + min((int) dt[1 - c].size(), id) + 1;
            } else {
                ans = id + min((int) dt[1 - c].size(), id + 1) + 1;
            }
            cout << ans << endl;
        }
    }
}


signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }
}
