#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long

using pii = pair <int, int>;
const int inf = 1e12;

vector <int> a;

struct segtree_max {
    vector <int> st;
    segtree_max(int n) {
        st.resize(4 * n);
    }
    void build(int v, int tl, int tr) {
        if (tr - tl == 1) {
            st[v] = a[tl];
            return;
        }
        int tm = (tl + tr) / 2;
        build(2 * v + 1, tl, tm);
        build(2 * v + 2, tm, tr);
        st[v] = max(st[2 * v + 1], st[2 * v + 2]);
    }
    void upd(int i, int x, int v, int tl, int tr) {
        if (tr - tl == 1) {
            st[v] = x;
            return;
        }
        int tm = (tl + tr) / 2;
        if (i < tm) upd(i, x, 2 * v + 1, tl, tm);
        else upd(i, x, 2 * v + 2, tm, tr);
        st[v] = max(st[2 * v + 1], st[2 * v + 2]);
    }
    int get(int ql, int qr, int v, int tl, int tr) {
        if (tl >= qr || tr <= ql) return -inf;
        if (tl >= ql && tr <= qr) return st[v];
        int tm = (tl + tr) / 2;
        return max(get(ql, qr, 2 * v + 1, tl, tm), get(ql, qr, 2 * v + 2, tm, tr));
    }
};


struct segtree_min {
    vector <int> st;
    segtree_min(int n) {
        st.resize(4 * n);
    }
    void build(int v, int tl, int tr) {
        if (tr - tl == 1) {
            st[v] = a[tl];
            return;
        }
        int tm = (tl + tr) / 2;
        build(2 * v + 1, tl, tm);
        build(2 * v + 2, tm, tr);
        st[v] = min(st[2 * v + 1], st[2 * v + 2]);
    }
    void upd(int i, int x, int v, int tl, int tr) {
        if (tr - tl == 1) {
            st[v] = x;
            return;
        }
        int tm = (tl + tr) / 2;
        if (i < tm) upd(i, x, 2 * v + 1, tl, tm);
        else upd(i, x, 2 * v + 2, tm, tr);
        st[v] = min(st[2 * v + 1], st[2 * v + 2]);
    }
    int get(int ql, int qr, int v, int tl, int tr) {
        if (tl >= qr || tr <= ql) return inf;
        if (tl >= ql && tr <= qr) return st[v];
        int tm = (tl + tr) / 2;
        return min(get(ql, qr, 2 * v + 1, tl, tm), get(ql, qr, 2 * v + 2, tm, tr));
    }
};

int near(int x, int n, segtree_max &tx, segtree_min &tn, int v, int tl, int tr) {
    int mx = tx.get(tl, tr, 0, 0,  n);
    int mn = tn.get(tl, tr, 0, 0, n);
    if (mx == -inf || mn == inf) return -1;
    if (mx == x && mn == x) return -1;
    if (tr - tl == 1) return tl;
    int tm = (tl + tr) / 2;
    int ans = near(x, n, tx, tn, 2 * v + 1, tl, tm);
    return ans == -1 ? near(x, n, tx, tn, 2 * v + 2, tm, tr) : ans;
}

vector <int> used(2e5 + 1), rev(2e5 + 1);
vector <pii> buf;

void build(int n, segtree_max &tx, segtree_min &tn) {
    buf = {{0, a[0]}};
    tx.upd(0, -inf, 0, 0, n);
    tn.upd(0, inf, 0, 0, n);
    used.assign(n + 1, 0);
    used[0] = 1;
    int id = 1;
    rev[1] = id++;
    int lst = a[0];
    for (int _ = 0; _ < n - 1; ++_) {
        auto i = near(lst, n, tx, tn, 0, 0, n);
        if (i == -1) break;
        used[i] = 1;
        rev[i + 1] = id++;
        buf.emplace_back(i, a[i]);
        lst = a[i];
        tx.upd(i, -inf, 0, 0, n);
        tn.upd(i, inf, 0, 0, n);
    }
    while (!buf.empty()) {
        auto [i, x] = buf.back();
        buf.pop_back();
        tx.upd(i, x, 0, 0, n);
        tn.upd(i, x, 0, 0, n);
    }
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            rev[i + 1] = id++;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q; cin >> n >> q;
    a.resize(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    segtree_max tx = segtree_max(n);
    segtree_min tn = segtree_min(n);
    tx.build(0, 0, n);
    tn.build(0, 0, n);
    build(n, tx, tn);
    while (q--) {
        int type; cin >> type;
        if (type == 1) {
            int i; cin >> i;
            tx.upd(i - 1, a[i], 0, 0, n);
            tx.upd(i, a[i - 1], 0, 0, n);
            tn.upd(i - 1, a[i], 0, 0, n);
            tn.upd(i, a[i - 1], 0, 0, n);
            swap(a[i - 1], a[i]);
            build(n, tx, tn);
        } else {
            int x; cin >> x;
            cout << rev[x] << '\n';
        }
    }
}