#include <bits/stdc++.h>
using namespace std;


#define int long long
#define line cout << "\n"
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(a) (int) a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pii pair<int, int>

typedef string str;
typedef long long ll;
typedef long double ld;


void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (auto &u : a) {
        cin >> u;
    }
    vector<vector<int>> pos(n + 1);
    for (int i = 0; i < n; i++) {
        pos[a[i]].pb(i);
    }
    vector<int> mi_idx(n + 1);
    while (q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            swap(a[x - 1], a[x]);
            for (int i = 1; i <= n; i++) {
                pos[i].clear();
            }
            for (int i = 0; i < n; i++) {
                pos[a[i]].pb(i);
            }
        } else {
            set<pair<int, pii>> st;
            for (int i = 1; i <= n; i++) {
                if (pos[i].empty()) {
                    continue;
                }
                st.insert({pos[i][0], {i, 0}});
            }
            int cur = 0;
            x--;
            for (int i = 1; i <= n; i++) {
                if (cur == x) {
                    cout << i; line;
                    break;
                }
                int val = a[cur];
                auto it = st.lower_bound({cur, {0, 0}});
                int p = it->second.second;
                st.erase(it);
                if (sz(pos[val]) != p + 1) {
                    st.insert({pos[val][p + 1], {val, p + 1}});
                }
                it = st.begin();
                if (it->second.first != val) {
                    cur = it->first;
                    continue;
                } else {
                    if (sz(st) == 1) {
                        cur = it->first;
                        continue;
                    }
                    ++it;
                    cur = it->first;
                }
            }
        }
    }
}


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


#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}