#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#include<random>
#include<chrono> 
using namespace std;
using ll = long long;
using ld = long double;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx")

#define int long long
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 998244353;

int bin(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) {
            res = a * res % mod;
        }
        n /= 2;
        a = a * a % mod;
    }
    return res;
}

vector<vector<int>> g;
vector<int> sz;

void dfs(int v) {
    sz[v] = 1;
    for (auto to : g[v]) {
        dfs(to);
        sz[v] += sz[to];
    }
}

int goy(int x) {
    return (x % mod + mod) % mod; 
}

vector<pii> t;

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

void upd(int v, int l, int r, int pos, int val) {
    if (r - l == 1) {
        t[v] = {l, val};
        return;
    }
    int m = (l + r) / 2;
    if (pos < m) {
        upd(2 * v + 1, l, m, pos, val);
    } else {
        upd(2 * v + 2, m, r, pos, val);
    }
    t[v] = min(t[2 * v + 1], t[2 * v + 2]);
}

const int inf = 1e9 + 1;

pii get(int v, int l, int r, int ql, int qr) {
    if (qr <= l || r <= ql) return {inf, inf};
    if (ql <= l && r <= qr) return t[v];
    int m = (l + r) / 2;
    return min(get(2 * v + 1, l, m, ql, qr), get(2 * v + 1, m, r, ql, qr));
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        v[i]--;
    }
    t.resize(4 * n);
    vector<int> pos(n);
    int c = 0, c1 = 0;
    for (int i = 0; i < n; ++i) {
        if (v[i] == 0) {
            pos[i] = ++c;
        } else {
            pos[i] = ++c1;
        }
    }
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int a, b;
            cin >> a;
            --a;
            swap(v[a], v[a + 1]);
        } else {
            int id;
            cin >> id;
            --id;
            if (v[id] == 0) {
                if (pos[id] > c1) {
                    cout << c1 + pos[id] << '\n';
                } else if (v[0] == 0) {
                    cout << pos[id] * 2 - 1 << '\n';
                } else {
                    cout << pos[id] * 2 << '\n';
                }
            } else {
                if (pos[id] > c) {
                    cout << c + pos[id] << '\n';
                } else if (v[0] == 1) {
                    cout << pos[id] * 2 - 1 << '\n';
                } else {
                    cout << pos[id] * 2 << '\n';
                }
            }
        }
    }
}

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