#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = int;
ll MOD = 998244353;

vector<ll> rev(vector<ll> p) {
    reverse(p.begin(), p.end());
    return p;
}

vector<ll> raz(vector<ll> p) {
    for (auto &i : p) i = p.size() - i + 1;
    return p;
}

vector<ll> obr(vector<ll> p) {
    vector<ll> q(p.size());
    for (ll i = 0;i < p.size();i++) q[p[i] - 1] = i + 1;
    return q;
}

ll mul(ll a, ll b) {
    return a * b % MOD;
}

ll bp(ll a, ll b) {
    if (b == 0) return 1;
    if (b == 1) return a;
    if (b % 2 == 0) {
        ll x = bp(a, b / 2);
        return mul(x, x);
    }
    else {
        return mul(a, bp(a, b - 1));
    }
}

ll calc(vector<ll> p) {
    ll sum = 0;
    for (ll i = 0;i < p.size();i++) {
        sum = (sum + bp(p[i], i + 1)) % MOD;
    }
    return sum;
}

void viperr() {
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (auto &i : a) cin >> i;
    while (q--) {
        ll t;
        cin >> t;
        if (t == 1) {
            ll x;
            cin >> x;
            swap(a[x - 1], a[x]);
        }
        else {
            vector<vector<ll>> col(n);
            for (ll i = 0;i < n;i++) {
                col[a[i] - 1].push_back(i);
            }
            unordered_set<ll> b;
            vector<ll> l(n);
            for (ll i = 0;i < n;i++) b.insert(i);
            vector<ll> qu;
            for (ll k = 0;k < n;k++) {
                ll fm = -1, sm = -1;
                vector<ll> s;
                for (auto i : b) {
                    if (l[i] < col[i].size()) {
                        if (fm == -1) {
                            fm = i;
                        }
                        else if (col[fm][l[fm]] > col[i][l[i]]) {
                            sm = fm;
                            fm = i;
                        }
                        else if (sm == -1 || col[sm][l[sm]] > col[i][l[i]]) {
                            sm = i;
                        }
                    }
                    else {
                        s.push_back(i);
                    }
                }
                for (auto i : s) b.erase(i);
                if (fm == -1) continue;
                l[fm]++;
                if (sm != -1) l[sm]++;
                if (qu.empty()) {
                    qu.push_back(col[fm][l[fm] - 1]);
                    if (sm != -1) qu.push_back(col[sm][l[sm] - 1]);
                }
                else {
                    if (a[qu.back()] == a[col[fm][l[fm] - 1]]) {
                        if (sm != -1) qu.push_back(col[sm][l[sm] - 1]);
                        qu.push_back(col[fm][l[fm] - 1]);
                    }
                    else {
                        qu.push_back(col[fm][l[fm] - 1]);
                        if (sm != -1) qu.push_back(col[sm][l[sm] - 1]);
                    }
                }
            }
            ll x;
            cin >> x;
            for (ll i = 0;i < n;i++) {
                if (qu[i] == x - 1) {
                    cout << i + 1 << '\n';
                    break;
                }
            }
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll ttt1 = 1;
    // cin >> ttt1;
    while (ttt1--) {
        viperr();
        cout << '\n';
    }
}