#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define o_set tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
#define int long long

signed main() {
    int n, q;
    cin >> n >> q;
    vector<int> o(n);
    vector<set<int> > p(n);
    set<pair<int, int> > st;
    vector<bool> l;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        o[i] = x;
        o[i]--;
        p[x - 1].insert(i);
    }
/*
    10 9
    3 1 1 2 2 1 1 2 2 2
    2 2
    2 3
    2 4
    2 10
    1 1
    2 2
    2 3
    2 4
    2 5
 */
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int pos;
            cin >> pos;
            swap(o[pos - 1], o[pos]);
        } else {
            p.clear();
            p.resize(n);
            for (int i = 0; i < n; i++) {
                p[o[i]].insert(i);
            }
            st.clear();
            vector<int> ll(n, 1);
            for (int i = 0; i < n; i++) {
                if (p[i].size()) {
                    st.insert({*p[i].begin(), i});
                    p[i].erase(p[i].begin());
                }
            }
            int x;
            cin >> x;
            x--;
            if (x==9) {
                cout <<"";
            }
            int last = 0;
            int col = 1;
            st.erase({last, o[last]});
            if (p[o[last]].size()) {
                st.insert({*p[o[last]].begin(), o[last]});
            }
            while (last != x) {
                if (st.begin()->second == o[last] && st.size() == 1) {
                    last = st.begin()->first;
                } else {
                    if (st.begin()->second == o[last]) {
                        auto it = st.begin();
                        it++;
                        last = it->first;
                    } else {
                        last = st.begin()->first;
                    }
                }
                st.erase({last, o[last]});
                if (!p[o[last]].empty()) {
                    st.insert({*p[o[last]].begin(), o[last]});
                    p[o[last]].erase(p[o[last]].begin());
                }
                col++;
            }
            cout << col << endl;
        }
    }

}
