#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#else
#pragma GCC optimize("O3,Ofast")
#pragma GCC target("avx2")
#endif

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;

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

void solve();

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#else
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    auto timer = chrono::high_resolution_clock().now().time_since_epoch().count()/1000;
    cout << "DEBUG TIMER: ";
    int ss = timer / 1000000;
    int mm = ss / 60;
    int hh = mm / 60 + 3;
    cout << hh % 24 << ':' << mm % 60 << ':' << ss % 60 << "\n";
#endif
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

// #define int ll

inline void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> v(n);
    oset st[2];
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        int ti = v[i] == v[0];
        st[ti].insert(i);
    }
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            int ind;
            cin >> ind;
            if (v[ind] == v[ind - 1]) continue;
            int ti = v[ind - 1] == v[0];
            swap(v[ind], v[ind - 1]);
            st[ti].erase(ind - 1);
            st[ti].insert(ind);
            st[1 - ti].erase(ind);
            st[1 - ti].insert(ind - 1);
        }else {
            int ind;
            cin >> ind;
            ind--;
            int ti = v[ind] == v[0];
            int ci = st[ti].order_of_key(ind) + 1;
            int co = st[1 - ti].size();
            co = min(co, ci - ti);
            cout << ci + co << '\n';
        }
    }
}



