#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <ext/pb_ds/assoc_container.hpp>

#define all(a) a.begin(), a.end()

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int &e : a) {
        cin >> e;
        e--;
    }
    vector<oset<int>> ids(2);
    for (int i = 0; i < n; ++i) {
        ids[a[i]].insert(i);
    }
    int t, x;
    while (q--) {
        cin >> t >> x;
        if (t == 1) {
            if (a[x - 1] == a[x]) continue;
            ids[a[x - 1]].erase(x - 1);
            ids[a[x]].erase(x);

            swap(a[x - 1], a[x]);
            ids[a[x - 1]].insert(x - 1);
            ids[a[x]].insert(x);
        } else {
            x--;
            int i = ids[a[x]].order_of_key(x);
            int j = ids[1 - a[x]].order_of_key(x);
            if (a[0] == a[x]) {
                cout << min(i + i + 1, i + j + 1) << '\n';
            } else {
                cout << min(i + i + 2, i + j + 2) << '\n';
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
}