#include <bits/stdc++.h>
/*#pragma GCC optimize("O3,unrool-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")*/
#define int long long

using namespace std;
int n;
void f(vector <int> &a, vector <int>&res1, vector <int> &idx1) {
    queue <int> bunc;
    int b=-1;
    vector <int> res;
    int pred=-1;
    for (int i=0; i<n; ++i) {
        if (!bunc.empty() && b!=pred) {
            res.push_back(bunc.front());
            bunc.pop();
            pred=a[res.back()];
        }
        if (a[i]==pred) {
            b=a[i];
            bunc.push(i);
            continue;
        }
        res.push_back(i);
        pred=a[i];
    }
    while (!bunc.empty()) {
        res.push_back(bunc.front());
        bunc.pop();
    }
    vector <int> idx(n);
    for (int i = 0; i < n; ++i) {
            idx[res[i]] = i;
        }
    res1=res,idx1=idx;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int q;
    cin >>n >>q;
    vector <int> a(n);
    for (int i=0; i<n; ++i) {
        cin >>a[i];
    }
    queue <int> bunc;
    int b=-1;
    vector <int> res;
    int pred=-1;
    for (int i=0; i<n; ++i) {
        if (!bunc.empty() && b!=pred) {
            res.push_back(bunc.front());
            bunc.pop();
            pred=a[res.back()];
        }
        if (a[i]==pred) {
            b=a[i];
            bunc.push(i);
            continue;
        }
        res.push_back(i);
        pred=a[i];
    }
    while (!bunc.empty()) {
        res.push_back(bunc.front());
        bunc.pop();
    }
    vector <int> idx(n);
    for (int i = 0; i < n; ++i) {
        idx[res[i]] = i;
    }
    while (q--) {
        int t;
        cin >>t;
        if (t==1) {
            int x;
            cin >>x;
            x--;
            if (a[x]==a[x+1])continue;
            int id=idx[x];
            int id2=idx[x+1];
            int mn=min(id,id2),mx=max(id,id2);
            if (mn==0 || a[res[mn-1]]==a[x] || a[res[mn-1]]==a[x+1]) {
                swap(res[id],res[id+1]);
                idx[x]=id2,idx[x+1]=id;
                swap(a[x],a[x+1]);
                continue;
            }
            if (id2==n-1 || a[res[mx+1]]!=a[x]/* || a[res[mx+1]]!=a[x+1]*/) {
                swap(a[x],a[x+1]);
                continue;
            }
            swap(a[x],a[x+1]);
            f(a,res,idx);
        }
        else {
            int y;
            cin >>y;
            y--;
            cout <<idx[y] <<'\n';
        }
    }
}
