#include <bits/stdc++.h>
using namespace std;

template<typename T>
istream& operator>>(istream& stream, vector<T>& a) {
    for (auto& x : a) stream >> x;
    return stream;
}
template<typename T>
ostream& operator<<(ostream& stream, vector<T>& a) {
    for (auto& x : a) stream << x << ' ';
    cout << '\n';
    return stream;
}
template<typename T1, typename T2>
istream& operator>>(istream& stream, vector<pair<T1, T2>>& a) {
    for (auto& [x, y] : a) stream >> x >>  y;
    return stream;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& stream, vector<pair<T1, T2>>& a) {
    for (auto& [x, y] : a) stream << x << ' ' << y << '\n';
    return stream;
}
template<typename T1, typename T2>
inline void amax(T1& a, T2 b) {
    a = max(a, b);
}
template<typename T1, typename T2>
inline void amin(T1& a, T2 b) {
    a = min(a, b);
}

//#define int int64_t
#define all(x) x.begin(), x.end()
#define pb emplace_back
#define ff first
#define ss second
#define sz(x) (int)(x.size())
#define deb cout << "----------------------" << endl
#define MIN(x) *min_element(all(x))
#define MINID(x) min_element(all(x)) - x.begin()
#define MAX(x) *max_element(all(x))
#define MAXID(x) max_element(all(x)) - x.begin()
#define push emplace
#define SUM(x) accumulate(all(x), 0ll)
#define sj(x) sort(all(x)), x.erase(unique(all(x)), x.end())

mt19937 rnd(221);

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using vvpi = vector<vpi>;
using ld = long double;

const int64_t INF = 1e18;
const int INF2 = 1e9;
const int mod = 1e9 + 7;
const ld eps = 1e-6;


const int N = 1e5 + 2323;
const int D = 500;

struct Segtree {
    struct Node {
        int s = 0;
        int mi = INF2;
        int ma = -INF2;
        Node operator+(const Node& b) const {
            Node res;
            res.s = b.s + s;
            res.mi = min(mi, b.mi);
            res.ma = max(ma, b.ma);
            return res;
        }
    };
    Node N = { 0, INF2, -INF2 };
    vector<Node> t;
    Segtree(int sz) : t(4 * sz) {}
    void build(int v, int l, int r, vi& a) {
        if (l + 1 == r) {
            t[v] = { a[l], a[l], a[l] };
            return;
        }
        int m = (l + r) / 2;
        build(v * 2, l, m, a);
        build(v * 2 + 1, m, r, a);
        t[v] = t[v * 2] + t[v * 2 + 1];
    }
    void upd(int v, int l, int r, int i, int x) {
        if (l + 1 == r) {
            t[v] = { x, x, x };
            return;
        }
        int m = (l + r) / 2;
        if (i < m) {
            upd(v * 2, l, m, i, x);
        }
        else {
            upd(v * 2 + 1, m, r, i, x);
        }
        t[v] = t[v * 2] + t[v * 2 + 1];
    }
    Node get(int v, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) return t[v];
        if (l >= qr || r <= ql) return N;
        int m = (l + r) / 2;
        return get(v * 2, l, m, ql, qr)
            + get(v * 2 + 1, m, r, ql, qr);
    }
};

void solve() {
    int n, q; cin >> n >> q;
    vi a(n); cin >> a;
    //a[i] <= 2
    Segtree tree1(n), tree2(n);
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 2) {
            cnt2++;
            tree2.upd(1, 0, n, i, 1);
        } else {
            cnt1++;
            tree1.upd(1, 0, n, i, 1);
        }
    }
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int x; cin >> x;
            if (a[x] != a[x - 1]) {
                if (a[x] == 1) {
                    tree1.upd(1, 0, n, x, 0);
                    tree1.upd(1, 0, n, x - 1, 1);
                    tree2.upd(1, 0, n, x - 1, 0);
                    tree2.upd(1, 0, n, x, 1);
                } else {
                    tree1.upd(1, 0, n, x - 1, 0);
                    tree1.upd(1, 0, n, x, 1);
                    tree2.upd(1, 0, n, x, 0);
                    tree2.upd(1, 0, n, x - 1, 1);
                }
            }
            swap(a[x], a[x - 1]);
        } else {
            int y; cin >> y;
            y--;
            if (a[y] == 1) {
                int nm = tree1.get(1, 0, n, 0, y + 1).s;
                if (cnt2 >= nm) {
                    if (a[0] == 1) {
                        cout << nm * 2 - 1 << '\n';
                    } else {
                        cout << nm * 2 << '\n';
                    }
                } else {
                    cout << cnt2 * 2 + (nm - cnt2) << '\n';
                }
            } else {
                int nm = tree2.get(1, 0, n, 0, y + 1).s;
                if (cnt1 >= nm) {
                    if (a[0] == 2) {
                        cout << nm * 2 - 1 << '\n';
                    } else {
                        cout << nm * 2 << '\n';
                    }
                } else {
                    cout << cnt1 * 2 + (nm - cnt1) << '\n';
                }
            }
        }
    }

}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        solve();
    }
}
