#include <iostream>
#include <vector>
#include <map>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;


#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ROF(i, a, b) for(ll i = b; i >= a; --i)

mt19937 rnd(42);
mt19937_64 rnd64(52);

const int N = 5e5;
struct BIT {
    vector<ll> f;
    ll n;
    BIT() {
        n = N;
        f.resize(n);
    }
    void update(ll pos, ll val) {
        for (; pos < n; pos = pos |(pos + 1)) {
            f[pos] += val;
        }
    }
    ll get(ll pos) {
        ll ans= 0;
        for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
            ans += f[pos];
        }
        return ans;
    }
};
BIT f[3];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (ll i= 0; i < n; ++i) {
        cin >> a[i];
        f[a[i]].update(i, 1);
    }
    for (ll i= 0; i < q; ++i) {
        ll t;
        cin >> t;
        if (t == 1) {
            ll pos; cin >> pos;
            f[a[pos - 1]].update(pos - 1, -1);
            f[a[pos]].update(pos, -1);
            swap(a[pos - 1], a[pos]);
            f[a[pos - 1]].update(pos - 1, 1);
            f[a[pos]].update(pos, 1);
        }
        else {
            ll x;
            cin >> x;
            --x;
            if (a[x] == 1) {
                ll cnt1 = f[1].get(x - 1);
                ll cnt2 = f[2].get(n - 1);
                if (cnt2 > cnt1) {
                    if (a[0] == 1) cout << cnt1 * 2 + 1 << '\n';
                    else cout << cnt1 * 2 + 2 << '\n';
                }
                else {
                    cout << cnt2 * 2 + (cnt1 - cnt2 + 1) << '\n';
                }
            }
            else {
                ll cnt2 = f[2].get(x - 1);
                ll cnt1 = f[1].get(n - 1);
                if (cnt1 > cnt2) {
                    if (a[0] == 2) cout << cnt2 * 2 + 1 << '\n';
                    else cout << cnt2 * 2 + 2 << '\n';
                }
                else {
                    cout << cnt1 * 2 + (cnt2 - cnt1 + 1) << '\n';
                }
            }
        }
    }
}