#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<ll> solve(vector<set<ll>> &a, ll n) {
    vector<set<ll>::iterator> its(n);
    set<pair<ll, ll>> b;
    for (ll i = 0; i < n; ++i) {
        if (!a[i].empty()) {
            b.insert({*a[i].begin(), i});
            its[i] = (++a[i].begin());
        }
    }

    ll last = -1, j = 0;
    vector<ll> ans(n);
    while (j < n) {
        if (b.size() == 1 || b.begin()->second != last) {
            auto [u, v] = *b.begin();
            ans[u] = j;
            b.erase(b.begin());
            last = v;
            if (its[v] != a[v].end()) {
                b.insert({*its[v], v});
                its[v]++;
            }
        }
        else {
            auto [u, v] = *(++b.begin());
            ans[u] = j;
            b.erase(++b.begin());
            last = v;
            if (its[v] != a[v].end()) {
                b.insert({*its[v], v});
                its[v]++;
            }
        }
        j++;
    }
    
    return ans;
}

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

    ll n, q;
    cin >> n >> q;

    vector<ll> arr(n);
    vector<set<ll>> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> arr[i];

        a[arr[i]].insert(i);
    }

    vector<ll> ans = solve(a, n);
    bool ready = true;
    while (q--) {
        ll t;
        cin >> t;

        if (t == 1) {
            ll x;
            cin >> x;
            x--;
            ll y = x + 1;

            a[arr[x]].erase(x);
            a[arr[y]].erase(y);
            a[arr[y]].insert(x);
            a[arr[x]].insert(y);

            swap(arr[x], arr[y]);
            ready = false;
        }
        else {
            ll x;
            cin >> x;
            x--;

            if (!ready)
                ans = solve(a, n);
            ready = true;

            cout << ans[x] + 1 << "\n";
        }
    }
}