#include <bits/stdc++.h>

using namespace std;
using ll = int64_t;
const ll inf = 1e18;
void solve();

template<typename T, typename T1> T remax(T& x, T1 y) { if (x < y) x = y; return x; }
template<typename T, typename T1> T remin(T& x, T1 y) { if (y < x) x = y; return x; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) solve();
}
#define int int64_t

void solve() {
    int n, q; cin >> n >> q;
    vector<int> a(n);
    for (auto& x : a) cin >> x;
    vector<set<int>> in(n + 1);
    for (int i = 0; i < n; ++i) in[a[i]].emplace(i);
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int id; cin >> id;
            id--;
            in[a[id]].erase(id);
            in[a[id + 1]].erase(id + 1);
            swap(a[id], a[id + 1]);
            in[a[id]].emplace(id);
            in[a[id + 1]].emplace(id + 1);
        } else {
            int y; cin >> y;
            --y;
            auto win = in;
            vector<int> pos(n);
            int it = 0, lst = 0;
            while (it < n) {
                int i = n, c = -1;
                for (int x = 1; x <= n; ++x) {
                    if (x == lst) continue;
                    if (!in[x].empty() && i > *in[x].begin()) {
                        c = x, i = *in[x].begin();
                    }
                }
                if (i == n) i = *in[lst].begin(), c = lst;
                pos[i] = it++;
                in[c].erase(i);
                lst = c;
            }
            in = win;
            cout << pos[y] + 1 << '\n';
        }
    }
}
