#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<set>
#include<cassert>
#include<climits>
using namespace std;
#define int long long
const int mod = 998244353;

struct segtree {
	int sz = 1;
	vector<int> t;

	void init(int n) {
		while (sz < n) sz *= 2;
		t.assign(2 * sz - 1, LLONG_MAX);
	}

	void upd(int x, int lx, int rx, int i, int xx) {
		if (rx - lx == 1) {
			t[x] = xx;
		}
		else {
			int m = (lx + rx) / 2;
			if (i < m) {
				upd(2 * x + 1, lx, m, i, xx);
			}
			else {
				upd(2 * x + 2, m, rx, i, xx);
			}
			t[x] = min(t[2 * x + 1], t[2 * x + 2]);
		}
	}

	int get(int x, int lx, int rx, int l, int r) {
		if (lx >= r || rx <= l) return LLONG_MAX;
		if (lx >= l && rx <= r) return t[x];
		int m = (lx + rx) / 2;
		int x1 = get(2 * x + 1, lx, m, l, r);
		int x2 = get(2 * x + 2, m, rx, l, r);
		return min(x1, x2);
	}
};

void solve() {
	int n, q;
	cin >> n >> q;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	vector<int> p1(n + 1), p2(n + 1); // p1[i] - true pos, p2[i] = pos in order
	vector<int> bl(n + 1, LLONG_MAX);
	segtree sg;
	unordered_map<int, int> mp;
	for (int i = n; i >= 1; i--) {
		if (mp[a[i]] != 0) {
			bl[i] = mp[a[i]];
		}
		mp[a[i]] = i;
	}
	sg.init(n + 2);
	for (auto par : mp) {
		int x = par.first;
		int xx = par.second;
		if (xx != 0) {
			sg.upd(0, 0, sg.sz, x, xx);
		}
	}
	int p = 1;
	int pp = 1;
	while (true) {
		int xx = bl[p];
		//cout << p << ' ' << xx << "\n";
		sg.upd(0, 0, sg.sz, a[p], xx);
		p1[pp] = p;
		p2[p] = pp;
		pp++;
		int mn = min(sg.get(0, 0, sg.sz, 1, a[p]),
			sg.get(0, 0, sg.sz, a[p] + 1, n + 2));
		if (mn == LLONG_MAX) {
			break;
		}
		p = mn;

	}
	if (pp <= n) {
		int xx = -1;
		for (int i = 1; i <= n; i++) {
			if (sg.get(0, 0, sg.sz, i, i + 1) != LLONG_MAX) {
				xx = sg.get(0, 0, sg.sz, i, i + 1);
				break;
			}
		}
		assert(xx != -1);
		//cout << pp;
		while (xx != LLONG_MAX) {
			p1[pp] = xx;
			p2[xx] = pp;
			pp++;
			xx = bl[xx];
		}
	}
	//cout << q;
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			int x;
			cin >> x;
			if (x == 1) {
				swap(a[x], a[x + 1]);
				mp.clear();
				bl.assign(n + 1, LLONG_MAX);
				p1.assign(n + 1, -1);
				p2.assign(n + 1, -1);
				for (int i = n; i >= 1; i--) {
					if (mp[a[i]] != 0) {
						bl[i] = mp[a[i]];
					}
					mp[a[i]] = i;
				}
				sg.init(n + 2);
				for (auto par : mp) {
					int x = par.first;
					int xx = par.second;
					if (xx != 0) {
						sg.upd(0, 0, sg.sz, x, xx);
					}
				}
				p = 1;
				pp = 1;
				while (true) {
					int xx = bl[p];
					sg.upd(0, 0, sg.sz, a[p], xx);
					p1[pp] = p;
					p2[p] = pp;
					pp++;
					int mn = min(sg.get(0, 0, sg.sz, 1, a[p]),
						sg.get(0, 0, sg.sz, a[p] + 1, n + 2));
					if (mn == LLONG_MAX) {
						break;
					}
					p = mn;
				}
				if (pp <= n) {
					int xx = -1;
					for (int i = 1; i <= n; i++) {
						if (sg.get(0, 0, sg.sz, i, i + 1) != LLONG_MAX) {
							xx = sg.get(0, 0, sg.sz, i, i + 1);
							break;
						}
					}
					assert(xx != -1);
					//cout << pp;
					while (xx != LLONG_MAX) {
						p1[pp] = xx;
						p2[xx] = pp;
						pp++;
						xx = bl[xx];
					}
				}
			}
			else {
				swap(p2[x], p2[x + 1]);
				swap(p1[x], p1[x + 1]);
			}
		}
		else {
			int x;
			cin >> x;
			cout << p2[x] << "\n";
		}
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
	}
	return 0;
}