#include <bits/extc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")

using namespace std;
using namespace __gnu_pbds;

const int inf = 2e9;

pair<int, int> maxmin(const pair<int, int> &a, const pair<int, int> &b) {
    return {max(a.first, b.first), min(a.second, b.second)};
}

struct segtree {
    int n;
    vector<pair<int, int>> t;

    segtree(int _n, const vector<int> &a) {
        n = _n;
        t.resize(4 * n, {-inf, inf});
        build(0, 0, n, a);
    }

    void build(int v, int l, int r, const vector<int> &a) {
        if (l + 1 == r) {
            t[v] = {a[l], a[l]};
        } else {
            int m = (l + r) / 2;
            build(2 * v + 1, l, m, a);
            build(2 * v + 2, m, r, a);
            t[v] = maxmin(t[2 * v + 1], t[2 * v + 2]);
        }
    }

    void update(int v, int l, int r, int i, pair<int, int> x) {
        if (l + 1 == r) {
            t[v] = x;
        } else {
            int m = (l + r) / 2;
            if (i < m) {
                update(2 * v + 1, l, m, i, x);
            } else {
                update(2 * v + 2, m, r, i, x);
            }
            t[v] = maxmin(t[2 * v + 1], t[2 * v + 2]);
        }
    }

    void update(int i, pair<int, int> x) {
        update(0, 0, n, i, x);
    }

    pair<int, int> query(int v, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) {
            return t[v];
        } else if (qr <= l || r <= ql) {
            return {-inf, inf};
        } else {
            int m = (l + r) / 2;
            return maxmin(query(2 * v + 1, l, m, ql, qr),
                        query(2 * v + 2, m, r, ql, qr));
        }
    }

    pair<int, int> query(int l, int r) {
        return query(0, 0, n, l, r);
    }
}; 

void solve() {
    int n, q; cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    segtree tree(n, a);
    set<int> un;
    for (int qi = 0; qi < q; ++qi) {
        int t, x; cin >> t >> x;
        if (t == 1) {
            swap(a[x], a[x - 1]);
        } else {
            --x;
            tree.build(0, 0, n, a);
            int time = 0;
            un.clear();
            for (int i = 0; i < n; ++i) {
                un.insert(i);
            }
            int last = -1;
            while (true) {
                int l = -1, r = n;
                while (r - l > 1) {
                    int m = (l + r) / 2;
                    auto cur = tree.query(0, m + 1);
                    if (cur != pair<int, int>{last, last} && cur != pair<int, int>{-inf, inf}) {
                        r = m;
                    } else {
                        l = m;
                    }
                }
                if (r == n) {
                    while (true) {
                        r = *un.begin();
                        un.erase(r);
                        ++time;
                        if (r == x) {
                            cout << time << '\n';
                            break;
                        }
                    }
                    break;
                }
                un.erase(r);
                ++time;
                if (r == x) {
                    cout << time << '\n';
                    break;
                }
                last = a[r];
                tree.update(r, {-inf, inf});
            }
        }
    }
}

signed main(void) {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
}