#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>

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

#define int ll

const int MOD = 998'244'353;
const int SIGNES = 6;
const int INF = 1e9;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    vector<int> idx(n);
    vector<deque<int>> colours(2);
    bool flag = true;
    {
        int t = 0;
        for (auto &i : a) {
            cin >> i;
            idx[t] = colours[i - 1].size();\
            if (i <= 2) {
                colours[i - 1].push_back(t++);
            }
            if (i > 2) {
                flag = false;
            }
            --i;
        }
    }
    if (true) {
        while (q--) {
            int c, x;
            cin >> c >> x;
            if (c == 1) {
                if (a[x - 1] != a[x]) {
                    swap(idx[x - 1], idx[x]);
                    swap(a[x - 1], a[x]);
                }
            } else {
                vector<int> used(n, 0);
                int t = 1;
                int last = -1;
                for (int i = 0; i < n; i++) {
                    if (used[i]) {
                        continue;
                    }
                    if (a[i] != last) {
                        used[i] = t++;
                    } else {
                        bool find = false;
                        for (int j = i + 1; j < n; j++) {
                            if (used[j]) {
                                continue;
                            } 
                            if (a[j] != last) {
                                find = true;
                                used[j] = t++;
                                break;
                            }
                        }
                        if (!find) {
                            last = -2;
                        }
                        used[i] = t++;
                    }
                    if (last != -2) {
                        last = a[i];
                    }
                }
                cout << used[x - 1] << '\n';
            }
        }
    } else {
        
        while (q--) {
            int c, x;
            cin >> c >> x;
            if (c == 1) {
                if (a[x - 1] != a[x]) {
                    colours[a[x - 1]][idx[x - 1]]++;
                    colours[a[x]][idx[x]]--;
                    swap(idx[x - 1], idx[x]);
                    swap(a[x - 1], a[x]);
                }
            } else {
                int cur_idx = idx[x - 1];
                int cur_col = a[x - 1];
                if (a[0] != cur_col) {
                    if (cur_idx >= colours[1 - cur_col].size()) {
                        cout << x << '\n';
                    } else {
                        cout << cur_idx * 2 + 2 << '\n';
                    }
                } else {
                    if (cur_idx >= colours[1 - cur_col].size()) {
                        cout << x << '\n';
                    } else {
                        cout << cur_idx * 2 + 1 << '\n';
                    }
                }
            }
        }
    }
}

signed main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(SIGNES);

    int q = 1;

    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    cin >> q;
    #endif

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

}