#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <deque>
#include <queue>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <random>
using namespace std;

#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
mt19937 rnd(time(0));
const int inf = 1e9 + 100;

void solve() {
	int n, q;
	cin >> n >> q;
	vector<vector<int>> col(2);
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
		col[a[i]].push_back(i);
	}
	col[0].push_back(inf);
	col[1].push_back(inf);
	vector<int> ans;
	vector<int> pos(n);
	int pref = -1;
	int l1 = 0, l2 = 0;
	for (int i = 0; i < n; i++) {
		if ((col[0][l1] < col[1][l2] and pref != 0) or col[1][l2] == inf) {
			ans.push_back(col[0][l1]);
			l1++;
			pref = 0;
		}
		else {
			ans.push_back(col[1][l2]);
			l2++;
			pref = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		pos[ans[i]] = i;
	}
	while (q--) {
		int t,v;
		cin >> t >> v;
		v--;
		if (t == 1) {
			if (a[v] == a[v + 1]) continue;
			swap(a[v], a[v + 1]);
			swap(pos[v], pos[v + 1]);
		}
		else {
			cout << pos[v] + 1 << '\n';
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	solve();
}