#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ff first
#define ss second

using namespace std;

vector <int> buildp(int n, vector <int> &a) {
    set <int> s;
    for (int i = 1; i < n; ++i) {
        s.insert(i);
    }
    vector <int> ans(n, 0);
    vector <int> cord(n, 0);
    for (int i = 1; i < n; ++i) {
        int t = *s.begin();
        for (auto v : s) {
            if (a[v] != a[ans[i - 1]]) {
                t = v;
                break;
            }
        }
        ans[i] = t;
        cord[t] = i;
        s.erase(t);
    }
    return cord;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector <int> a(n);
    int mx = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    if (mx <= 2) {
        vector <int> ind(n, 0);
        vector <vector <int>> cord(3);
        for (int i = 0; i < n; ++i) {
            ind[i] = cord[a[i]].size();
            cord[a[i]].push_back(i);
        }
        vector <int> sz(3);
        sz[1] = cord[1].size();
        sz[2] = cord[2].size();
        while (q--) {
            int t;
            cin >> t;
            if (t == 1) {
                int x;
                cin >> x;
                --x;
                if (a[x] == a[x + 1]) continue;
                swap(cord[a[x]][ind[x]], cord[a[x + 1]][ind[x + 1]]);
                swap(ind[x], ind[x + 1]);
                swap(a[x], a[x + 1]);
            } else {
                int y;
                cin >> y;
                --y;
                if (a[y] == a[0]) {
                    cout << min(sz[3 - a[y]], ind[y]) + ind[y] + 1 << '\n';
                } else {
                    cout << min(sz[3 - a[y]], ind[y] + 1) + ind[y] + 1 << '\n';
                }
            }
        }
        return;
    }
    vector <int> cord = buildp(n, a);
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            cin >> x;
            --x;
            swap(a[x], a[x + 1]);
            if (a[x] != a[x + 1] && x != 0)
                swap(cord[x], cord[x + 1]);
        } else {
            int i;
            cin >> i;
            cout << cord[i - 1] + 1 << '\n';
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int t = 1;
    while (t--) solve(), cout << '\n';
}