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

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define ll long long
#define pii pair<int, int>
#define tiii tuple<int ,int, int >
#define tiiii tuple<int, int, int, int>
#define tiiiii tuple<int, int, int, int, int>
#define ve vector
#define vi ve<int>
#define vvi ve<vi>
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define cin(a) for(auto &now : a) cin >> now;
#define print(a, s) for(auto now : a) cout << now << s;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(time(0));
const int N = 1e6 + 10;
const int M = 998244353;
int st(int a, int n) {
    if (n == 0) return 1;
    return (n % 2 == 0 ? st(a * a % M, n / 2) : a * st(a, n - 1) % M);
}

void solve() {
    int n, q; cin >> n >> q;
    vi a(n); cin(a); a.push_back(-1);
    vi c1(n);c1[0] = (a[0] == 1);
    for (int i = 1; i < n; ++i) c1[i] = c1[i - 1] + (a[i] == 1);
    while (q--) {
        int t, x; cin >> t >> x; --x;
        if (t == 1) {
            if (a[x] == a[x + 1]) continue;
            if (a[x] == 1) {
                --c1[x];
            }
            else {
                ++c1[x];
            }
            swap(a[x], a[x + 1]);
        }
        else {
            if (a[x] == 1) cout << c1[x] - 1 + min(c1[x] - 1, n - c1.back()) + 1 << "\n";
            else cout << (x + 1 - c1[x]) - 1 + min((x + 1 - c1[x]), c1.back()) + 1 << "\n";
        }
    }
    // vi nxt(n); nxt[n - 1] = n;
    // vi ind(n),
    // for (int i = n - 2; i >= 0; --i) {
    //     if (a[i] == a[i + 1]) nxt[i] = nxt[i + 1];
    //     else nxt[i] = i + 1;
    // }
    // while (q--) {
    //     int t, x; cin >> t >> x; --x;
    //     if (t == 1) {
    //         swap(a[x], a[x + 1]);
    //         if (a[x + 1] == a[x + 2]) nxt[x + 1
    //     }
    // }

}
int32_t main() {
    // ios::sync_with_stdio(0);
    // cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(9);

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


