#ifdef LOCAL
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <ctime>
#include <climits>
#include <iomanip>
#include <numeric>
#include <random>
#include <array>
#include <bitset>
#include <unordered_map>
#include <unordered_set>

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define int long long

using ll = long long;
using ld = long double;
using namespace std;

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2>& p) {
	out << p.first << " " << p.second;
	return out;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
	for (auto& el : a) {
		in >> el;
	}
	return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T>& a) {
	if (a.empty()) return out;
	out << a[0];
	for (int i = 1; i < (int)a.size(); i++) {
		out << " " << a[i];
	}
	return out;
}

const int mod = 998244353;

int add(int x, int y) {
	if (x + y >= mod) return x + y - mod;
	return x + y;
}

int sub(int x, int y) {
	if (x < y) return x - y + mod;
	return x - y;
}

int mul(int x, int y) {
	return (1ll * x * y) % mod;
}

int bp(int x, int p) {
	if (p == 0) return 1;
	if (p == 1) return x;
	if (p % 2 == 0) {
		return bp(mul(x, x), p / 2);
	} else {
		return mul(x, bp(x, p - 1)) % mod;
	}
}


/*
int n, k;
vector<vector<int>> g;
vector<int> check;
vector<int> tin;
vector<int> tout;
vector<int> p;
vector<int> need;
int timer = 0;

void dfs(int v) {
	tin[v] = timer;
	timer++;
	for (auto& to : g[v]) {
		dfs(to);
	}
	tout[v] = timer;
	timer++;
}

bool par(int v, int u) {
	return (tin[v] <= tin[u] && tin[u] <= tout[v]);
}

int lca(int v, int u) {
	int v1 = v;
	while (!par(v1, u)) {
		v1 = p[v1];
	}
	return v1;
}

vector<int> take(k);
int have = 0;
int ans = 0;

void gen(int v) {
	if (n - v < k - have) return;
	if (v == n) {
		ans++;
		return;
	}
	gen(v + 1);
	for (int i = 0; i < k; i++) {
		int prev = take[i];
		int phave = have;
		int nxt = take[i];
		if (nxt == -1) {
			nxt = v;
		} else {
			nxt = lca(nxt, v);
		}
		if (par(nxt, need[i]) && nxt != need[i]) {
			continue;
		}
		if (nxt == need[i] && prev != need[i]) {
			have++;
		}
		take[i] = nxt;
		gen(v + 1);
		take[i] = prev;
		have = phave;
	}
}

void solve() {
	cin >> n >> k;
	g.resize(n);
	check.resize(n);
	tin.resize(n);
	tout.resize(n);
	p.resize(n);
	take.assign(k, -1);
	for (int i = 0; i < k; i++) {
		int v;
		cin >> v;
		v--;
		check[v] = 1;
		need.push_back(v);
	}
	for (int i = 1; i < n; i++) {
		cin >> p[i];
		p[i]--;
		g[p[i]].push_back(i);
	}
	dfs(0);
	gen(0);
	cout << ans;
}*/


void solve() {
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	cin >> a;
	for (int i = 0; i < n; i++) {
		a[i]--;
	}
	vector<vector<int>> pref(n, vector<int>(2));
	pref[0][a[0]] = 1;
	for (int i = 1; i < n; i++) {
		pref[i] = pref[i - 1];
		pref[i][a[i]]++;
	}
	vector<int> cnt = pref[n - 1];
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			int i;
			cin >> i;
			i--;
			pref[i][a[i]]--;
			pref[i][a[i + 1]]++;
			swap(a[i], a[i + 1]);
		} else {
			int y;
			cin >> y;
			y--;
			int ans = 0;
			if (a[y] == a[0]) {
				ans = pref[y][a[0]] + min(cnt[a[0] ^ 1], pref[y][a[0]] - 1);
			} else {
				ans = pref[y][a[y]] + min(cnt[a[y] ^ 1], pref[y][a[y]]);
			}
			cout << ans << "\n";
		}
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	ld start_time = clock();
#endif
	solve();
#ifdef LOCAL
	ld finish_time = clock();
	cout << "\n" << "finished in: " << (finish_time - start_time) / CLOCKS_PER_SEC;
#endif
	return 0;
}