// cf: stupid_moron
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int inf = 1e9 + 2145;
mt19937 rng(time(0));

const int N = 5e5 + 21;
int n, q, a[N];
int t[N];
void add(int i, int v) {
	for (; i <= n; i += i & -i)
		t[i] += v;
}
int sum(int i) {
	int r = 0;
	for (; i; i -= i & -i)
		r += t[i];
	return r;
}

void solve() {
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] == 1) add(i, 1);
	}

	while (q--) {
		int tt;
		cin >> tt;
		if (tt == 1) {
			int x;
			cin >> x;
			if (a[x] == 1) add(x, -1);
			if (a[x + 1] == 1) add(x + 1, -1);

			swap(a[x], a[x + 1]);

			if (a[x] == 1) add(x, 1);
			if (a[x + 1] == 1) add(x + 1, 1);
		} else {
			int y;
			cin >> y;
			int c = sum(y);

			int ans;
			if (a[y] == 1) 
				ans = 2 * c - 1;
			else 
				ans = 2 * c + 1;
			cout << ans << '\n';
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 1;
	// cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}