#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
int n, q;
vector<int> a;

void out(int x) {
    int cnt = 0;
    int lst = -1;
    vector<int> used(n + 1);
    for (int i = 1; i <= n; i++) {
        bool ok = 0;
        for (int j = 1; j <= n; j++) {
            if (a[j] != lst && !used[j]) {
                cnt++;
                used[j] = 1;
                ok = 1;
                lst = a[j];
                if (j == x) {
                    cout << cnt << '\n';
                    return;
                }
                break;
            }
        }
        if (!ok) {
            for (int j = 2; j <= n; j++) {
                if (!used[j]) {
                    cnt++;
                    lst = a[j];
                    used[j] = 1;
                    if (j == x) {
                        cout << cnt << '\n';
                        return;
                    }
                    break;
                }
            }
        }
    }
}

void slv() {
    vector<vector<int>> p(2);
    for (int i = 1; i <= n; i++) {
        p[a[i] - 1].push_back(i);
    }
    vector<int> pos;
    for (int i = 0; i < min(p[0].size(), p[1].size()); i++) {
        if (a[1] == 1) {
            pos.push_back(p[0][i]);
            pos.push_back(p[1][i]);
        }
        else {
            pos.push_back(p[1][i]);
            pos.push_back(p[0][i]);
        }
    }
    for (int i = min(p[0].size(), p[1].size()); i < p[0].size(); i++) {
        pos.push_back(p[0][i]);
    }
    for (int i = min(p[0].size(), p[1].size()); i < p[1].size(); i++) {
        pos.push_back(p[1][i]);
    }
    vector<int> cnt(n + 1);
    for (int i = 0; i < n; i++) {
        cnt[pos[i]] = i + 1;
    }
    while (q--) {
        int tp, x;
        cin >> tp >> x;
        if (tp == 2) {
            cout << cnt[x] << '\n';
        }
        else {
            if (a[x] != a[x + 1]) {
                swap(cnt[x], cnt[x + 1]);
                swap(a[x], a[x + 1]);
            }
        }
    }
}


void slv5() {
    vector<vector<int>> p(5);
    for (int i = 1; i <= n; i++) {
        p[a[i] - 1].push_back(i);
    }
    vector<int> pos;
    int t = min({p[0].size(), p[1].size(), p[2].size(), p[3].size(), p[4].size()});
    vector<int> pb, used(n + 1);
    for (int i = 1; i <= n; i++) {
        if (!used[a[i]]) {
            used[i] = 1;
            pb.push_back(a[i] - 1);
        }
    }
    for (int i = 0; i < t; i++) {
        for (int c : pb) {
            pos.push_back(p[c][i]);
        }
    }
    while (true) {
        for (int i = 0; i < 5; i++) {
            if (p[i].size() == t) {
                p[i].clear();
            }
        }
        int nt = 1e9;
        for (int i = 0; i < 5; i++) {
            if (p[i].size() > 0) {
                nt = min(nt, (int)p[i].size());
            }
        }
        if (nt == 1e9) {
            break;
        }
        for (int c : pb) {
            if (p[c].size() > t) {
                for (int i = t; i < nt; i++) {
                    pos.push_back(p[c][i]);
                }
            }
        }
        t = nt;
    }
    vector<int> cnt(n + 1);
    for (int i = 0; i < n; i++) {
        cnt[pos[i]] = i + 1;
    }
    while (q--) {
        int tp, x;
        cin >> tp >> x;
        if (tp == 2) {
            cout << cnt[x] << '\n';
        }
        else {
            if (a[x] != a[x + 1]) {
                swap(cnt[x], cnt[x + 1]);
                swap(a[x], a[x + 1]);
            }
        }
    }
}


void solve() {
    cin >> n >> q;
    a.resize(n + 1);
    int mx = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mx = max(a[i], mx);
    }
    if (mx <= 2) {
        slv();
        return;
    }
    if (mx <= 5) {
        slv5();
        return;
    }
    while (q--) {
        int tp, x;
        cin >> tp >> x;
        if (tp == 2) {
            out(x);
        }
        else {
            swap(a[x], a[x + 1]);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
