#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_set>
#include<deque>
using namespace std;
#define int long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
const int maxn = 5e5, mod = 998244353;

int a[maxn], b[maxn], n;

void upd(int i, int x) {
	for (int j = i; j < n; j = (j | (j + 1)))
		b[j] += x;
}

int get(int i) {
	int s = 0;
	for (int j = i; j >= 0; j = (j & (j + 1)) - 1)
		s += b[j];
	return s;
}

void solve() {
	int q;
	cin >> n >> q;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (a[i] == 1) upd(i, 1);
	}
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			int x;
			cin >> x;
			--x;
			if (a[x] != a[x + 1]) {
				if (a[x] == 1) {
					upd(x, -1);
					upd(x + 1, 1);
				}
				else {
					upd(x, 1);
					upd(x + 1, -1);
				}
			}
			swap(a[x], a[x + 1]);
		}
		else {
			int y;
			cin >> y;
			--y;
			if (a[y] == 1) {
				int c = get(y);
				if (a[0] == 1)
					cout << min(y + 1, (c - 1) * 2 + 1) << "\n";
				else
					cout << min(y + 1, c * 2) << "\n";
			}
			else {
				int c = y + 1 - get(y);
				if (a[0] == 1)
					cout << min(y + 1, c * 2) << "\n";
				else
					cout << min(y + 1, (c - 1) * 2 + 1) << "\n";
			}
		}
	}
}

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