#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>


using namespace std;
using ll = long long;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(0);

	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	vector<int> i1(n), i2(n);
	int c1 = 0, c2 = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] = min(a[i], 2);
		if (a[i] == 1) {
			i1[i] = c1;
			++c1;
		}
		else {
			i2[i] = c2;
			++c2;
		}
	}

	for (int i = 0; i < q; ++i) {
		int t;
		cin >> t;
		if (t == 1) {
			int x;
			cin >> x;
			if (a[x] == a[x - 1]) {
				continue;
			}
			swap(i1[x], i1[x - 1]);
			swap(i2[x], i2[x - 1]);
			swap(a[x], a[x - 1]);
		}
		else {
			int y;
			cin >> y;
			--y;
			if (a[y] == 1) {
				int f1 = min(c2, i1[y] + (a[0] == 2));
				cout << i1[y] + 1 + f1 << '\n';
			}
			else {
				int f2 = min(c1, i2[y] + (a[0] == 1));
				cout << i2[y] + 1 + f2 << '\n';
			}
		}
	}

	return 0;
}
