#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) {
        is >> i;
    }
    return is;
}

struct Fenwick {
    int n;
    vector<int> t;

    Fenwick(int _n) : n(_n) {
        t.resize(n + 1);
    }

    int get(int i) {
        int ans = 0;
        for (; i > 0; i -= i & (-i)) {
            ans += t[i];
        }
        return ans;
    }

    int get(int l, int r) {
        return get(r) - get(l);
    }

    void add(int i, int d) {
        for (++i; i <= n; i += i & (-i)) {
            t[i] += d;
        }
    }

    void upd(int i, int x) {
        int d = x - get(i, i + 1);
        add(i, d);
    }
};

int32_t main() {
#ifdef LOCAL
    freopen("C:\\work\\input.txt", "r", stdin);
#else
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    cin >> a;
    int cnt1 = 0, cnt2 = 0;
    for (auto i : a) {
        if (i == 1) {
            ++cnt1;
        } else {
            ++cnt2;
        }
    }
    Fenwick tr1(n), tr2(n);
    for (int i = 0; i < n; ++i) {
        if (a[i] == 1) {
            tr1.upd(i, 1);
        } else {
            tr2.upd(i, 1);
        }
    }
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            cin >> i;
            --i;
            swap(a[i], a[i + 1]);
            if (a[i] == 1) {
                tr1.upd(i, 1);
                tr2.upd(i, 0);
            } else {
                tr1.upd(i, 0);
                tr2.upd(i, 1);
            }
            if (a[i + 1] == 1) {
                tr1.upd(i + 1, 1);
                tr2.upd(i + 1, 0);
            } else {
                tr1.upd(i + 1, 0);
                tr2.upd(i + 1, 1);
            }
        } else {
            int y;
            cin >> y;
            --y;
            if (a[0] == 1) {
                if (a[y] == 1) {
                    int k = tr1.get(0, y + 1);
                    if (k <= min(cnt1, cnt2)) {
                        cout << (k - 1) * 2 + 1 << "\n";
                    } else {
                        cout << min(cnt1, cnt2) + k << "\n";
                    }
                } else {
                    int k = tr2.get(0, y + 1);
                    if (k <= min(cnt1, cnt2)) {
                        cout << (k - 1) * 2 + 2 << "\n";
                    } else {
                        cout << min(cnt1, cnt2) + k << "\n";
                    }
                }
            } else {
                if (a[y] == 1) {
                    int k = tr1.get(0, y + 1);
                    if (k <= min(cnt1, cnt2)) {
                        cout << (k - 1) * 2 + 2 << "\n";
                    } else {
                        cout << min(cnt1, cnt2) + k << "\n";
                    }
                } else {
                    int k = tr2.get(0, y + 1);
                    if (k <= min(cnt1, cnt2)) {
                        cout << (k - 1) * 2 + 1 << "\n";
                    } else {
                        cout << min(cnt1, cnt2) + k << "\n";
                    }
                }
            }
        }
    }
    return 0;
}
