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

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using uint = unsigned int;

using oset = tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x.size())

template<typename T>
void sort(T &s) {
    sort(all(s));
}

template<typename T>
void rsort(T &s) {
    sort(rall(s));
}

mt19937 rnd(264);

const int inf = 2e9 + 2000;
const ll infll = 2e18 + 2000;
const int st_R = 19;
const int R = (1 << st_R);
const int mod = 998244353;

struct Mod {
    int x = 0;
    Mod (int x) : x(x) {}
    Mod () = default;

    Mod operator + (const Mod o) const {
        if (x + o.x >= mod) {
            return x + o.x - mod;
        }
        return x + o.x;
    }

    Mod operator - (const Mod o) const {
        if (x - o.x < 0) {
            return x - o.x + mod;
        }
        return x - o.x;
    }

    Mod operator * (const Mod o) const {
        return ll(x) * ll(o.x) % ll(mod);
    }
};

Mod st(Mod x, int a) {
    Mod res = 1;
    while (a) {
        if (a & 1) {
            res = res * x;
        }
        x = x * x;
        a /= 2;
    }
    return res;
}

template<typename T>
struct point {
    T x, y;
    point(T x, T y) : x(x), y(y) {}
    point(point a, point b) : x(b.x - a.x), y(b.y - a.y) {}

    point operator + (const point o) const {
        return {x + o.x, y + o.y};
    }

    point operator - (const point o) const {
        return {x - o.x, y - o.y};
    }

    T operator * (const point o) const {
        return x * o.x + y * o.y;
    }

    T operator % (const point o) const {
        return x * o.y - y * o.x;
    }

    T len2() {
        return x * x + y * y;
    }

    ld len() {
        return sqrt(x * x + y * y);
    }
};

using Point = point<ll>;
using Vector = point<ll>;

struct Line {
    ld a, b, c;
    Line(ld a, ld b, ld c) : a(a), b(b), c(c) {}
    Line(Point p1, Point p2) : a(p1.y - p2.y), b(p2.x - p1.x), c(p1.x * p2.y - p2.x * p1.y) {}
};

struct Circle {
    Point c;
    ld r;
    Circle(Point c, ld r) : c(c), r(r) {}
};

vector<vector<int> > g;
vector<int> siz;

void dfs(int v, int pa = -1) {
    siz[v] = 1;
    for (auto u : g[v]) {
        if (u != pa) {
            dfs(u, v);
            siz[v] += siz[u];
        }
    }
}
oset a1, a2;
oset ks, ks2;

void del1(int x) {
    if (a1.find(x - 1) != a1.end()) {
        ks.erase(x - 1);
    }
    if (a1.find(x + 1) != a1.end()) {
        ks.erase(x);
    }
    a1.erase(x);
}

void add1(int x) {
    if (a1.find(x - 1) != a1.end()) {
        ks.insert(x - 1);
    }
    if (a1.find(x + 1) != a1.end()) {
        ks.insert(x);
    }
    a1.insert(x);
}

void del2(int x) {
    if (a2.find(x - 1) != a2.end()) {
        ks2.erase(x - 1);
    }
    if (a2.find(x + 1) != a2.end()) {
        ks2.erase(x);
    }
    a2.erase(x);
}

void add2(int x) {
    if (a2.find(x - 1) != a2.end()) {
        ks2.insert(x - 1);
    }
    if (a2.find(x + 1) != a2.end()) {
        ks2.insert(x);
    }
    a2.insert(x);
}

void solve() {
    int n, q;
    cin >> n >> q;

    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        int cf;
        cin >> cf;
        if (cf == 1) {
            a1.insert(i);
            if (a1.find(i - 1) != a1.end()) {
                ks.insert(i - 1);
            }
            c[i] = 1;
        } else {
            a2.insert(i);
            if (a2.find(i - 1) != a2.end()) {
                ks2.insert(i - 1);
            }
            c[i] = 2;
        }
    }

    for (int i = 0; i < q; ++i) {
        // for (auto j : a1) {
        //     cout << j << ' ';
        // }
        // cout << "\n";
        // for (auto j : a2) {
        //     cout << j << ' ';
        // }
        // cout << "\n! ";
        // for (auto j : ks) {
        //     cout << j << ' ';
        // }
        // cout << "\n";
        int ty, x;
        cin >> ty >> x;
        x--;
        if (ty == 1) {
            if (c[x] != c[x + 1]) {
                if (c[x] == 1) {
                    del1(x);
                    del2(x + 1);
                    add1(x + 1);
                    add2(x);
                } else {
                    del2(x);
                    del1(x + 1);
                    add2(x + 1);
                    add1(x);
                }
                swap(c[x], c[x + 1]);
            }
        } else {
            if (c[x] == 1) {
                int k1 = a1.order_of_key(x);
                int kp = ks.order_of_key(x);
                int kp2 = ks2.order_of_key(x);
                cout << a1.order_of_key(x) + 1 + k1 + max(0, kp2 - kp) << "\n";
            } else {
                int k1 = a1.order_of_key(x);
                int kp = ks.order_of_key(x);
                int kp2 = ks2.order_of_key(x);
                cout << a2.order_of_key(x) + 1 + k1 - max(0, kp - kp2) << "\n";
            }
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int tt = 1;
    // cin >> tt;

    while (tt--) {
        solve();
    }
}
