#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <algorithm>
#include <chrono>
#include <random>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define its(a) a.begin(), a.end()
#define scan(a) {for (int i = 0; i < a.size(); ++i) cin >> a[i];}
constexpr ll INFLL = 1e18 + 130;
constexpr int INFINT = 1e9 + 13;
constexpr int MAXN = 1e6;
constexpr int LOGN = 18;
constexpr int M = 998'244'353;
std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());

int binPow(int a, int n) {
	if (!n) return 1;
	if (n & 1) return 1ll * a * binPow(a, n - 1) % M;
	return binPow(1ll * a * a % M, n / 2);
}

struct Fenwick {
	int n;
	vector <int> tree;

	void init(int n) {
		this->n = n;
		tree.assign(n + 1, 0);
	}

	void update(int i, int x) {
		for (++i; i <= n; i += (i & (-i))) {
			tree[i] += x;
		}
	}

	int get_pref(int i) {
		int res = 0;
		for (++i; i > 0; i -= (i & (-i))) {
			res += tree[i];
		}
		return res;
	}
};

void solve() {
	int n, q; cin >> n >> q;
	vector <int> a(n);
	Fenwick cnt0, cnt1; cnt0.init(n); cnt1.init(n);
	int all1 = 0, all0 = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i]; a[i]--;
		if (a[i]) {
			all1++; cnt1.update(i, 1);
		}
		else {
			all0++;
			cnt0.update(i, 1);
		}
	}
	while (q--) {
		int type; cin >> type;
		if (type & 1) {
			int x; cin >> x; x--;
			if (a[x]) {
				cnt1.update(x, -1);
				cnt1.update(x + 1, 1);
			}
			else {
				cnt0.update(x, -1);
				cnt0.update(x + 1, 1);
			}
			if (a[x + 1]) {
				cnt1.update(x + 1, -1);
				cnt1.update(x, 1);
			}
			else {
				cnt0.update(x + 1, -1);
				cnt0.update(x, 1);
			}
		}
		else {
			int y; cin >> y; y--;
			if (a[y] == 0) {
				int c0 = cnt0.get_pref(y - 1);
				if (a[0] == a[y]) {
					cout << c0 + min(c0, all1) + 1 << "\n";
				}
				else {
					cout << c0 + min(c0 + 1, all1) + 1 << "\n";
				}
			}
			else {
				int c1 = cnt1.get_pref(y - 1);
				if (a[0] == a[y]) {
					cout << c1 + min(c1, all0) + 1 << "\n";
				}
				else {
					cout << c1 + min(c1 + 1, all0) + 1 << "\n";
				}
			}
		}
	}
}


int gen(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rnd);
}

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	solve();
}

/*
7 5
2 1 1 2 1 1 2
2 1
2 2
2 3
2 4
2 5
*/