#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#define all(p) p.begin(),p.end()
using namespace std;
// #define int long long
int n;
int a[500001];
int cur[500001];
int pos[500001];
void build() {
    int ans = 0;
    int pt = 1;
    int ptt = 0;
    int sz = 0;
    int pr = 0;
    for (int i = 1; i <= n; i++) {
        if (i == n || a[i + 1] != a[i]) {
            while (ptt < sz && pt <= i && a[cur[ptt]] != a[pt]) {
                int d = cur[ptt];
                int b = pt;
                if (pr == a[d]) {
                    swap(d, b);
                }
                ans++;
                pos[d] = ans;
                ans++;
                pos[b] = ans;
                pr = a[b];
                ptt++;
                pt++;
            }
            for (int j = pt; j <= i; j++) {
                cur[sz++] = j;
            }
            pt = i + 1;
        }
    }
    while (ptt < sz) {
        ans++;
        pos[cur[ptt]] = ans;
        ptt++;
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    bool ch = 0;
    int mn = INT_MAX;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            cin >> x;
            swap(a[x], a[x + 1]);
            mn = min(mn, a[x]);
            ch = 0;
        } else {
            int x;
            cin >> x;
            if (!ch && mn < x) {
                build();
                ch = 1;
                mn = INT_MAX;
            }
            cout << pos[x] << endl;
            // for (auto u : ans) {
            //     cout << u << ' ';
            // }
            // cout << endl;
        }
    }
}