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

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

const int MOD = 998244353;
const int INFi = 1e9;
const ll INF = 1e18;

using namespace __gnu_pbds;
using namespace std;

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

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    auto b = a;
    sort(b.begin(), b.end());
    b.resize(unique(b.begin(), b.end()) - b.begin());
    for (int i = 0; i < n; i++) {
        a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    }
    vector<set<int>> s(n);
    for (int j = 0; j < n; j++) {
        s[a[j]].insert(j);
    }
    for (int i = 0; i < q; i++) {
        int type;
        cin >> type;
        int x;
        cin >> x;
        x--;
        if (type == 1) {
            s[a[x]].erase(x);
            s[a[x + 1]].erase(x + 1);
            swap(a[x], a[x + 1]);
            s[a[x]].insert(x);
            s[a[x + 1]].insert(x + 1);
        } else {
            auto s2 = s;
            int cur = 0, clr;
            int ans = 1;
            for (int j = 0; j < n; j++) {
                if (s[j].find(cur) != s[j].end()) {
                    clr = j;
                    break;
                }
            }
            s2[clr].erase(s2[clr].begin());
            while (cur != x) {
                int mn = n, clr2 = -1;
                for (int j = 0; j < n; j++) {
                    if (s2[j].empty() || j == clr) {
                        continue;
                    }
                    if (*s2[j].begin() < mn) {
                        mn = *s2[j].begin();
                        clr2 = j;
                    }
                }
                //cout << mn << ' ' << clr2 << ' ' << ans << '\n';
                if (mn == n) {
                    while (cur != x) {
                        cur = *s2[clr].begin();
                        s2[clr].erase(s2[clr].begin());
                        ans++;
                    }
                } else {
                    ans++;
                    cur = mn;
                    clr = clr2;
                    s2[clr2].erase(s2[clr2].begin());
                }
            }
            cout << ans << '\n';
        }
    }
}
