#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

// #pragma GCC optimize("O3,unroll-loops,fast-math")
// #pragma GCC target("avx2,bmi2")

using namespace std;
using namespace chrono;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T, typename Cmp = less<T>>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, Cmp,
__gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
inline int sz(const T& x) {
    return (int)x.size();
}

const int MAXN = 1e6;
const int INF = 2e9;
const int ALPH = 26;
const int MAXLOG = 20;
const ll MOD = 998244353;
const ld EPS = 1e-8;

const ull SEED = steady_clock::now().time_since_epoch().count();
mt19937_64 rnd(67);

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> colours(n);
    ordered_set<int> col1, col2;
    for (int i = 0; i < n; i++) {
        cin >> colours[i];
        if (colours[i] == 1) {
            col1.insert(i);
        } else {
            col2.insert(i);
        }
    }
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int x;
            cin >> x; x--;
            if (colours[x] != colours[x + 1]) {
                if (colours[x] == 1) {
                    col1.erase(x);
                    col2.insert(x);
                    col2.erase(x + 1);
                    col1.insert(x + 1);
                    swap(colours[x], colours[x + 1]);
                } else {
                    col2.erase(x);
                    col1.insert(x);
                    col1.erase(x + 1);
                    col2.insert(x + 1);
                    swap(colours[x], colours[x + 1]);
                }
            }
        } else {
            int y;
            cin >> y; y--;
            if (colours[y] == 1) {
                int idx = col1.order_of_key(y);
                if (idx < sz(col2)) {
                    cout << 2 * (idx + 1) - (colours[0] == 1) << '\n';
                } else {
                    cout << sz(col2) + idx + 1 << '\n';
                }
            } else {
                int idx = col2.order_of_key(y);
                if (idx < sz(col1)) {
                    cout << 2 * (idx + 1) - (colours[0] == 2) << '\n';
                } else {
                    cout << sz(col1) + idx + 1 << '\n';
                }
            }
        }
    }
}

int main() {
    #ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test_cases = 1;
    // cin >> test_cases;
    while (test_cases--) solve();
    return 0;
}
