#include<bits/stdc++.h>

#define int long long

using namespace std;

const int MAX = 5e5 + 1;
int cnt_p[MAX];
int sz_go[MAX];
int cl_ls[MAX];
int cnt_sf[MAX];

vector<int> solve(vector<int> a) {
    int n = (int)a.size();
    vector<int> ans(n);
    queue<int> go;
    int ls = 0;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        while (!go.empty() && a[go.front()] != ls) {
            ans[go.front()] = cnt;
            cnt++;
            ls = a[go.front()];
            go.pop();
        }
        cl_ls[i] = ls;
        sz_go[i] = (int)go.size();
        cnt_p[i] = cnt;
        if (a[i] != ls) {
            ans[i] = cnt;
            cnt++;
            ls = a[i];
        } else {
            go.push(i);
        }
    }
    while (!go.empty()) {
        ans[go.front()] = cnt;
        cnt++;
        go.pop();
    }
    vector<int> ncnt(n + 1);
    for (int i = n - 1; i >= 0; --i) {
        cnt_sf[i] = ncnt[a[i]];
        ncnt[a[i]]++;
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> js = solve(a);
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            cin >> x;
            if (a[x] == a[x - 1]) continue;
            swap(cnt_sf[x], cnt_sf[x - 1]);
            int ls = cl_ls[x - 1];
            int go_cl = ls;
            int gos = sz_go[x - 1];
            int cnt = cnt_p[x - 1];
            swap(a[x], a[x - 1]);
            for (int j = x - 1; j < x + 5; ++j) {
                while (gos > 0 && ls != go_cl) {
                    cnt++;
                    gos--;
                    ls = go_cl;
                }
                cl_ls[j] = ls;
                sz_go[j] = gos;
                cnt_p[j] = cnt;
                if (a[j] != ls) {
                    cnt++;
                    ls = a[j];
                } else {
                    gos++;
                    go_cl = a[j];
                }
            }
        } else {
            int y;
            cin >> y;
            y--;
            if (cl_ls[y] != a[y]) {
                cout << cnt_p[y] + 1 << endl;
            } else {
                cout << cnt_p[y] + sz_go[y] + min(sz_go[y] + 1, n - y - 1 - cnt_sf[y]) + 1 << endl;
            }
        }
    }
    return 0;
}

