// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <bits/extc++.h>


// #pragma GCC target("avx2")
using namespace __gnu_pbds;
using ll = long long;
#define int ll

using namespace std;

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int mod = 998244353;
struct Mint {
    int val;
    Mint() {
        val = 0;
    }
    Mint(int x) {
        x %= mod;
        if (x < 0) x += mod;
        val = x;
    }
};
Mint operator+=(Mint& a, Mint b) {
    a.val += b.val;
    if (a.val >= mod) a.val -= mod;
    return a;
}
Mint operator-=(Mint& a, Mint b) {
    a.val -= b.val;
    if (a.val < 0) a.val += mod;
    return a;
}
Mint operator+(Mint a, Mint b) {
    a += b;
    return a;
}
Mint operator-(Mint a, Mint b) {
    a -= b;
    return a;
}
Mint operator*=(Mint& a, Mint b) {
    a.val = 1ll * a.val * b.val % mod;
    return a;
}
Mint operator*(Mint a, Mint b) {
    a *= b;
    return a;
}
Mint binpow(Mint x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    if (p % 2 == 0) {
        return binpow(x * x, p / 2);
    }
    return x * binpow(x, p - 1);
}
void solve() {
    int n, q; cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    oset<int> inds1, inds2;
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) inds1.insert(i);
        else inds2.insert(i);
    }
    int c1 = inds1.size();
    int c2 = inds2.size();
    while (q --> 0) {
        int t; cin >> t;
        if (t == 1) {
            int x; cin >> x;
            x--;
            if (a[x] == a[x + 1]) continue;
            if (a[x] == 1) {
                inds1.erase(inds1.find(x));
                inds1.insert(x + 1);
            } else {
                inds2.erase(inds2.find(x));
                inds2.insert(x + 1);    
            }
            if (a[x + 1] == 1) {
                inds1.erase(inds1.find(x + 1));
                inds1.insert(x);
            } else {
                inds2.erase(inds2.find(x + 1));
                inds2.insert(x);    
            }
            swap(a[x], a[x + 1]);
        } else {
            int y; cin >> y; y--;
            int ind;
            if (a[y] == 1) {
                ind = inds1.order_of_key(y);
                if (a[0] == 1) {
                    if (c1 > c2) {
                        cout << c2 * 2 + (ind - c2) + 1 << "\n";
                    } else {
                        cout << ind * 2 + 1 << "\n";
                    }
                } else {
                    if (c1 > c2) {
                        cout << c2 * 2 + (ind - c2) << "\n";
                    } else {
                        cout << ind * 2 + 2 << "\n";
                    }
                }
            } else {
                ind = inds2.order_of_key(y);
                if (a[0] == 2) {
                    if (c2 > c1) {
                        cout << c1 * 2 + (ind - c1) + 1 << "\n";
                    } else {
                        cout << ind * 2 + 1 << "\n";
                    }
                } else {
                    if (c2 > c1) {
                        cout << c1 * 2 + (ind - c1) << "\n";
                    } else {
                        cout << ind * 2 + 2 << "\n";
                    }
                }
            }
            // int cnt = 0;
            // int last = -1;
            // vector<int> used(n);
            // while (cnt != n) {
            //     bool f = 0, f1 = 0;
            //     for (int i = 0; i < n; i++) {
            //         if (!used[i] && (last == -1 || a[i] != last)) {
            //             cnt++;
            //             used[i] = 1;
            //             f1 = 1;
            //             last = a[i];
                        
            //             if (i == y) {
            //                 cout << cnt << "\n";
            //                 f = 1;
            //                 break;
            //             }
            //             break;
            //         }
            //     }
                
                // if (f) break;
                // if (!f1) {
                //     for (int i = 0; i < n; i++) {
                //         if (!used[i]) {
                //             cnt++;
                //             used[i] = 1;
                //             if (i == y) {
                //                 cout << cnt << "\n";
                //                 f = 1;
                //                 break;
                //             }
                //         } 
                //     }
                // }
                // if (f) break;
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t --> 0) solve();
}