#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#pragma GCC optimize('O3')
#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]--;
        x--;
        p[x].insert(i);
    }
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int x;
            cin >> x;
            x--;
            p[o[x]].erase(p[o[x]].find(x));
            p[o[x + 1]].erase(p[o[x]].find(x + 1));
            p[o[x]].insert(x + 1);
            p[o[x +1 ]].insert(x);
            swap(o[x], o[x + 1]);
        }else {
            int pos;
            cin >> pos;
            pos--;
            int y = distance(p[o[pos]].begin(), p[o[pos]].find(pos));
            if (pos == 0) {
                cout << 1 << endl;
                continue;
            }
            int ans = 0;
            if (o[0] == o[y]) {
                ans = min((long long)p[o[0]].size(), y + 1);
                ans += y +1;
            }else {
                y--;
                ans = min((long long)p[o[0] ^ 1].size(), y + 1);
                ans += y +1 ;
                ans++;
            }
            cout << ans << endl;
        }
    }

}
