#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5e5 + 5;
const int INF = 1e9 + 5;

struct El {
    int x, c;
};

vector<El> tree(4 * MAXN);
vector<int> a(MAXN, INF);

void build(int i, int l, int r) {
    if (r - l == 1) {
        tree[i] = {a[l], 1};
        return;
    }
    int m = (r + l) / 2;
    build(2 * i + 1, l, m);
    build(2 * i + 2, m, r);
    if (tree[2 * i + 1].x < tree[2 * i + 2].x) {
        tree[i] = tree[2 * i + 1];
    } else if (tree[2 * i + 1].x > tree[2 * i + 2].x) {
        tree[i] = tree[2 * i + 2];
    } else {
        tree[i] = {tree[2 * i + 1].x, tree[2 * i + 1].c + tree[2 * i + 2].c};
    }
}

void upd(int i, int l, int r, int ql, int qx) {
    if (r <= ql || ql < l) {
        return;
    }
    if (r - l == 1) {
        tree[i].x = qx;
        return;
    }
    int m = (r + l) / 2;
    upd(2 * i + 1, l, m, ql, qx);
    upd(2 * i + 2, m, r, ql, qx);
    if (tree[2 * i + 1].x < tree[2 * i + 2].x) {
        tree[i] = tree[2 * i + 1];
    } else if (tree[2 * i + 1].x > tree[2 * i + 2].x) {
        tree[i] = tree[2 * i + 2];
    } else {
        tree[i] = {tree[2 * i + 1].x, tree[2 * i + 1].c + tree[2 * i + 2].c};
    }
}

El get(int i, int l, int r, int ql, int qr) {
    if (r <= ql || qr <= l) {
        return {0, 0};
    }
    if (ql <= l && r <= qr) {
        return tree[i];
    }
    int m = (r + l) / 2;
    El x = get(2 * i + 1, l, m, ql, qr);
    El y = get(2 * i + 2, m, r, ql, qr);
    if (x.x < y.x) {
        return y;
    } else if (y.x < x.x) {
        return x;
    }
    return {x.x, x.c + y.c};
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    int pos = INF;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 1) {
            pos = min(pos, i);
        }
    }
    build(0, 0, MAXN);
    while (q--) {
        int tip;
        cin >> tip;
        if (tip == 1) {
            int i;
            cin >> i;
            i--;
            upd(0, 0, MAXN, i, a[i + 1]);
            upd(0, 0, MAXN, i + 1, a[i]);
            swap(a[i], a[i + 1]);
            continue;
        }
        int ind;
        cin >> ind;
        ind--;
        if (ind <= pos) {
            //while (true) {}
            cout << ind + 1 << '\n';
            continue;
        }
        El x = get(0, 0, MAXN, pos, ind);
        int c2 = ind - pos - x.c;
        if (x.c < c2) {
            while (true) {}
            cout << ind + 1 << '\n';
            continue;
        }
        if (a[ind] == 1) {
            x.c++;
            El y = get(0, 0, MAXN, ind + 1, n);
            int c3 = 0;
            if (y.x == 1) {
                c3 = n - (ind + 1) - y.c;
            } else {
                c3 = y.c;
            }
            if (c3 + c2 >= x.c) {
                while (true) {}
                cout << ind + (x.c - c2) << '\n';
            } else {
                while (true) {}
                cout << ind + c3 + (x.c - c2 - c3) << '\n';
            }
            continue;
        }
        c2++;
        if (x.c <= c2) {
            while (true) {}
            cout << ind + 1 << '\n';
        } else {
            if (pos == 0) {
                //while (true) {}
                cout << 2 * c2 - 1 << '\n';
            } else {
                //while (true) {}
                cout << 2 * c2 << '\n';
            }
        }
    }
}
