// #pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using ld = long double;

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

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

    int n, q;
    cin >> n >> q;

    vi a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    if (a[0] == 2) {
        for (int &x : a)  x = 3 - x;
    }

    vi used;

    vi bad(n);

    int cnt1 = 0;
    int cnt2 = 0;

    for (int i = 0; i < n; ++i) {
        if (a[i] == 1) cnt1++;
        if (a[i] == 2) cnt2++;
        if (a[i] == 1) bad[i] = cnt2;
        else bad[i] = cnt1;
    }

    for (int id = 0; id < q; ++id) {
        int t;
        cin >> t;

        if (t == 1) {
            int x;
            cin >> x;
            --x;
            swap(a[x], a[x + 1]);
            if (a[x] != a[x + 1]) {
                swap(bad[x], bad[x + 1]);
                --bad[x];
                ++bad[x + 1];
            }
        } else {
            int y;
            cin >> y;
            --y;

            int cur = y - bad[y];
            int ans = 0;

            if (a[y] != a[0]) {
                if (bad[y] <= cur) {
                    ans = 2 * bad[y];
                    ans += cur - bad[y];
                    ++ans;
                } else {
                    ans = 2 * cur + 2;
                }
            } else {
                if (bad[y] < cur) {
                    ans = 2 * bad[y];
                    ans += cur - bad[y];
                    ++ans;
                } else {
                    ans = 2 * cur + 1;
                }
            }

            cout << ans << '\n';
        }
    }
}