#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using V = vector<ll>;
using VV = vector<V>;
using VVV = vector<VV>;
using VVVV = vector<VVV>;
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define Alexander_Babin int main()
#define Philipp_Gribov void solve()
#define Vorg_Cup void build()
#define Ivan_Argunov ull binpow(ull a, ull n)

mt19937 rnd('zalupa');
const ull base = 83;
const ull mod = 998244353;
Ivan_Argunov {
    ull ans = 1;
    while (n) {
        if (n&1) ans = ans * a % mod;
        n >>= 1;
        a = a * a % mod;
    }
    return ans;
}
ull pows[1000001];
ull rpows[1000001];
ull fact[1000001];
ull rfact[1000001];
Vorg_Cup {
    pows[0] = 1;
    rpows[0] = 1;
    fact[0] = 1;
    rfact[0] = 1;
    for (int i=1;i<=1000000;i++) {
        pows[i] = pows[i-1] * base;
        fact[i] = fact[i-1] * i;
        //pows[i] = pows[i-1] * base % mod;
        //rpows[i] = binpow(pows[i], mod-2);
        //fact[i] = fact[i-1] * i % mod;
        //rfact[i] = binpow(fact[i], mod-2);
    }
}

struct sparse_table {
    int n;
    V a;
    VV sparses;
    void init(V _a){
        a = _a;
        n = _a.size();
        sparses.assign(__lg(n)+1,V(n));
        sparses[0] = _a;
        for (int j=1;j<=__lg(n);j++)
            for (int i=0;i+(1<<j)-1<n;i++)
                sparses[j][i]=min(sparses[j-1][i],sparses[j-1][i+(1<<(j-1))]);
    }
    int get(int l, int r) {
        int x = __lg(r-l+1);
        return min(sparses[x][l],sparses[x][r-(1<<x)+1]);
    }
};

struct furry_tree {
    int n;
    V a;
    V val;
    void upd(int i, int x) {
        for (;i<=n;i+=i&(-i))
            val[i]+=x;
    }
    void init(int _n) {
        n = _n;
        a.assign(n,0);
        val.assign(n+1,0);
    }
    // void init(V _a) {
    //     a = _a;
    //     n = _a.size();
    //     val.assign(n+1,0);
    //     for (int i=0;i<n;i++)
    //         upd(i+1,a[i]);
    // }
    int gett(int r) {
        int ans = 0;
        for (;r>0;r-=r&(-r))
            ans+=val[r];
        return ans;
    }
    int get(int l, int r) {
        return gett(r+1)-gett(l);
    }
};

// int n,k;
// VV graph;
// VV dp;
// VB is_task;


Philipp_Gribov {
    int n,q; cin >> n >> q;
    V a(n); for (auto &x:a) cin >> x;
    furry_tree f; f.init(n);
    for (int i=0;i<n;i++)
        if (a[i]==1)
            f.upd(i+1,1);
    int big_cnt_not_one = n-f.get(0,n-1);
    int big_cnt_one = f.get(0,n-1);
    while (q--) {
        int tip; cin >> tip;
        if (tip==1) {
            int i; cin >> i; i--;
            if (a[i]==1)
                f.upd(i+1,-1);
            if (a[i+1]==1)
                f.upd(i+2,-1);
            swap(a[i],a[i+1]);
            if (a[i]==1)
                f.upd(i+1,1);
            if (a[i+1]==1)
                f.upd(i+2,1);
        } else {
            int i; cin >> i; i--;
            int cnt_one = f.get(0,i);
            int cnt_not_one = i+1-f.get(0,i);
            if (a[i]==1) {
                if (cnt_one>=big_cnt_not_one) {
                    cout << cnt_one+big_cnt_not_one << '\n';
                } else {
                    cout << cnt_one*2-1 << '\n';
                }
            } else {
                if (cnt_not_one==big_cnt_one) {
                    cout << cnt_one+cnt_not_one << '\n';
                } else {
                    cout << 2*cnt_not_one << '\n';
                }
            }
        }
    }
}

Alexander_Babin {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
}
