#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;

const ll mod = 998244353;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    int cnt = 0;
    for (auto& i : a) {
        cin >> i;
        if (i != 1)
            cnt++;
    }
    vector<int> pr(n, 0);
    int type, i;
    pr[0] = (a[0] == 1);
    for (int i = 1; i < n; ++i)
        pr[i] = pr[i - 1] + (a[i] == 1);
    while (q--) {
        cin >> type >> i;
        i--;
        if (type == 1) {
            if (a[i] != a[i + 1]) {
                if (a[i] == 1) {
                    pr[i]--;
                } else if (a[i + 1] == 1) {
                    pr[i]++;
                }
            }
            swap(a[i], a[i + 1]);
        } else {
            if (a[i] == 1) {
                if (pr[i] > cnt)
                    cout << cnt * 2 + pr[i] - cnt << '\n';
                else
                    cout << pr[i] * 2 - 1 << '\n';
            } else if (pr[i] * 2 >= i + 1) {
                cout << (i + 1 - pr[i]) * 2 << '\n';
            } else {
                cout << i + 1 << '\n';
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}
