#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);
    tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> s[2];
    for (int i = 0; i < n; ++i) {
        cin >> a[i]; --a[i];
        s[a[i]].insert(i);
    }
    segtree tree(n, a);
    set<int> un;
    for (int qi = 0; qi < q; ++qi) {
        int t, x; cin >> t >> x;
        if (t == 1) {
            s[a[x]].erase(x);
            s[a[x - 1]].erase(x - 1);
            swap(a[x], a[x - 1]);
            s[a[x]].insert(x);
            s[a[x - 1]].insert(x - 1);
        } else {
            --x;
            int pos = 1 + s[a[x]].order_of_key(x);
            int asz = s[a[x]].size();
            int dsz = s[1 - a[x]].size();
            if (a[0] == a[x]) {
                cout << pos + min(dsz, pos - 1) << '\n';
            } else {
                cout << min(pos, dsz) + pos << '\n';
            }
        }
    }
}

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

/*
10 10
2 1 1 2 2 1 1 2 2 2
2 2
2 3
2 4
2 10
1 1
2 2
2 3
2 4
2 5
2 10
*/