#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 ll long long
#define ld long double
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define int long long

typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    vector<ordered_set> g(2);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i]--;
        g[a[i]].insert(i);
    }
    for (int i = 0; i < q; ++i) {
        int type, ind;
        cin >> type >> ind;
        ind--;
        if (type == 1) {
            int kol0 = g[a[ind]].order_of_key(a[ind]), kol1 = g[a[ind] ^ 1].order_of_key(a[ind]);
            bool was = false;
            if (a[0] == a[ind]) {
                was = true;
            }
            if (was) {
                if (kol0 <= kol1) {
                    cout << kol0 * 2 + 1 << "\n";
                } else {
                    cout << kol0 + kol1 + 1 << "\n";
                }
            } else {
                if (kol0 < kol1) {
                    cout << kol0 * 2 + 2 << "\n";
                } else {
                    cout << kol0 + kol1 + 1 << "\n";
                }
            }
        } else {
            if (a[ind] != a[ind + 1]) {
                g[a[ind] ^ 1].insert(ind);
                g[a[ind]].erase(ind);
                ind++;
                g[a[ind] ^ 1].insert(ind);
                g[a[ind]].erase(ind);
                swap(a[ind], a[ind - 1]);
            }
        }
    }
    return 0;
}