#ifndef LOCAL
#pragma GCC Optimize("O3, Ofast")
#pragma GCC Target("avx,avx2,unroll-loops")
#endif
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define int ll
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#ifndef LOCAL
#define endl "\n"
#endif

mt19937 rnd(time(0));
int took[10001];

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (auto &x : a) {
        cin >> x;
    }
    vector<int> pref0 = {0}, pref1 = {0};
    for (int i = 0; i < n; ++i) {
        pref0.pb(pref0.back());
        pref1.pb(pref1.back());
        if (a[i] == 1) {
            pref0.back()++;
        } else {
            pref1.back()++;
        }
    }
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            cin >> x;
            --x;
            swap(a[x], a[x + 1]);
            pref0[x + 1] = pref0[x] + (a[x] == 1);
            pref1[x + 1] = pref1[x] + (a[x] == 2);
        } else {
            memset(took, 0, sizeof(took));
            int y;
            cin >> y;
            --y;
            int one = pref1[y], zero = pref0[y];
            int tot1 = pref1.back(), tot0 = pref0.back();
            bool sw = false;
            if (a[0] == 2) {
                sw = true;
                swap(one, zero);
                swap(tot0, tot1);
            }
            if ((a[y] == 1) != sw) {
                cout << zero + min(zero, tot1) + 1 << endl;
            } else {
                cout << one + min(one + 1, tot0) + 1 << endl;
            }
        }
    }
}

signed main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #else
        ios::sync_with_stdio(false);
        cin.tie(0);
    #endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}