#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi")

using namespace std;
// using namespace __gnu_pbds;
// template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve();

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int t = 1;
    while (t--) {
        solve();
    }
}

#define int long long
const int MAXN = 2e5, MOD = 998244353, INF = 2e18;


void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    vector<int> pref1(n + 1), pref2(n  + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pref1[i] = pref1[i-1];
        pref2[i] = pref2[i-1];
        if (a[i] == 1) {
            pref1[i]++;
        }else {
            pref2[i]++;
        }
    }
    while (q--) {
        int z;
        cin >> z;
        if (z == 1) {
            int l;
            cin >> l;
            if (a[l] == 1) {
                pref1[l]--;
                pref2[l]++;
            } else {
                pref2[l]--;
                pref1[l]++;
            }
            swap(a[l], a[l+1]);
        } else {
            int y;
            cin >> y;
            int pr1 = pref1[y];
            int pr2 = pref2[y];
            if (a[0] == 1) {
                if (pr1 <= pr2) {
                    if (a[y] == 1) {
                        cout << pr1 * 2-1 << '\n';
                    } else {
                        int cnt = pref1[n] - pr1;
                        if (pr2 - pr1 > cnt) {
                            cout << pref1[n] * 2 + pr2-(pr1+cnt) << '\n';
                        } else {
                            cout << pr1 * 2 + (pr2-pr1) * 2-1 << '\n';
                        }
                    }
                } else {
                    if (a[y] == 1) {
                        int cnt = pref2[n] - pr2;
                        if (pr1 - pr2 > cnt) {
                            cout << pref2[n] * 2 + pr1-(pr2+cnt) << '\n';
                        } else {
                            cout << pr2 * 2 + (pr1-pr2) * 2 << '\n';
                        }
                    } else {
                        cout << pr2 * 2 << '\n';
                    }
                }
            } else {
                if (pr1 <= pr2) {
                    if (a[y] == 1) {
                        cout << pr1 * 2 << '\n';
                    } else {
                        int cnt = pref1[n] - pr1;
                        if (pr2 - pr1 > cnt) {
                            cout << pref1[n] * 2 + pr2-(pr1+cnt) << '\n';
                        } else {
                            cout << pr1 * 2 + (pr2-pr1) * 2-1 << '\n';
                        }
                    }
                } else {
                    if (a[y] == 1) {
                        int cnt = pref2[n] - pr2;
                        if (pr1 - pr2 > cnt) {
                            cout << pref2[n] * 2 + pr1-(pr2+cnt) << '\n';
                        } else {
                            cout << pr2 * 2 + (pr1-pr2) * 2 << '\n';
                        }
                    } else {
                        cout << pr2 * 2-1 << '\n';
                    }
                }
            }
        }
    }
}
