#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using ll = long long;
using ld = long double;
mt19937 rnd(1245);

#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll mod = 998244353;
const ll inf = 1e9;
const ll INF = 1e18;
const int maxn = 1e5 + 1;
const int logn = 21;
const int sq = 350;
const ld eps = 1e-8;
const ld pi = acos(-1);

ll mmod(ll x, ll mod = mod) {
    x %= mod;
    if (x < 0) x += mod;
    return x;
}

ll gcd(ll a, ll b) {
    ll res;
    while (b != 0) {
        res = a;
        a = b;
        b = res % a;
    }
    return a;
}

ll binpow(ll a, ll n, ll mod = mod) {
    ll res = 1;
    while (n != 0) {
        if (n & 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> bl(n, n), prev(n, 0), cnt(n, 1);
    int b1 = -1, b0 = -1;
    int cnt1 = 0, cnt0 = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == 1) {
            if (b1 != -1) {
                bl[b1] = i;
                prev[i] = b1;
                cnt[i] = cnt[b1] + 1;
            }
            b1 = i;
            cnt1++;
        }
        else {
            if (b0 != -1) {
                bl[b0] = i;
                prev[i] = b0;
                cnt[i] = cnt[b0] + 1;
            }
            b0 = i;
            cnt0++;
        }
    }

    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int x;
            cin >> x;
            if (a[x - 1] == 1 && a[x] == 1) {
                continue;
            }
            if (a[x - 1] != 1 && a[x] != 1) {
                continue;
            }
            swap(prev[x], prev[x  - 1]);
            swap(bl[x], bl[x - 1]);
            swap(cnt[x], cnt[x - 1]);
            swap(a[x], a[x - 1]);
        }
        else {
            int x;
            cin >> x;
            if (a[x - 1] == 1) {
                if (cnt[x - 1] > cnt0) {
                    cout << cnt0 + cnt[x - 1] << '\n';
                }
                else {
                    if (a[0] == 1) {
                        cout << 2 * cnt[x - 1] - 1 << '\n';
                    }
                    else {
                        cout << 2 * cnt[x - 1] << '\n';
                    }
                }
            }
            else {
                if (cnt[x - 1] > cnt1) {
                    cout << cnt1 + cnt[x - 1] << '\n';
                }
                else {
                    if (a[0] == 1) {
                        cout << 2 * cnt[x - 1] << '\n';
                    }
                    else {
                        cout << 2 * cnt[x - 1] - 1 << '\n';
                    }
                }
            }
        }
    }



}

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }

}