#include <iostream>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

#define int long long

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

const int INTI = 2e9 + 5, MAXN = 1e5 + 1, MOD = 1e9 + 7;
const ll INF = 4e18 + 5;

vector<int> color;

void solve() {
    int n, q;
    cin >> n >> q;
    color.resize(n);
    for (auto& i : color)
        cin >> i;
    if (n <= 10000 && q <= 10000) {
        while (q--) {
            int fl;
            cin >> fl;
            if (fl == 1) {
                int x;
                cin >> x;
                swap(color[x], color[x - 1]);
            } else {
                queue<int> q;
                int col = -1;
                int pos;
                cin >> pos;
                pos--;
                int last = -1, temp = 0, pov = -1;
                for (int i = 0; i < n; ++i) {
                    if (color[i] != last) {
                        if (i == pos) {
                            cout << temp + 1 << '\n';
                            break;
                        }
                        temp++;
                        last = color[i];
                        //cout << i << ' ' << temp << '\n';
                        if (q.size()) {
                            last = pov;
                            if (pos == q.front()) {
                                cout << temp + 1 << '\n';
                                break;
                            }
                            temp++;
                            q.pop();
                        }
                    } else {
                        pov = last;
                        q.push(i);
                    }
                    if (i == n - 1) {
                        while (q.size()) {
                            if (pos == q.front())
                                cout << temp + 1 << '\n';
                            temp++;
                            q.pop();
                        }
                    }
                }
            }
        }
        return;
    }
    vector<int> pref(n);
    pref[0] = bool(color[0] == 1);
    for (int i = 1; i < n; ++i)
        pref[i] = pref[i - 1] + (color[i] == 1);
    while (q--) {
        int fl;
        cin >> fl;
        if (fl == 1) {
            int x;
            cin >> x;
            if (color[x] != color[x - 1]) {
                if (color[x] == 1)
                    pref[x - 1]++;
                else
                    pref[x - 1]--;
                swap(color[x], color[x - 1]);
            }
        } else {
            int v;
            cin >> v;
            v--;
            if (color[v] == 1) {
                int x = min(pref[v], v - pref[v]);
                cout << 2 * x + pref[v] - x + min(n - pref[n] - x, pref[v] - x - (color[0] == 1)) << '\n';
            } else {
                int pr = v - pref[v], pn = n - pref[n];
                int x = min(pr, v - pr);
                cout << 2 * x + pr - x + min(n - pn - x, pr - x - (color[0] == 1)) << '\n';
            }
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}
