#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define asc(x) x.begin(), x.end()
#define des(x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back
#define ll long long
#define db long double
#define fori(a, b) for (int i = (a); i < (b); ++i)
#define forj(a, b) for (int j = (a); j < (b); ++j)

using namespace std;
// using namespace __gnu_pbds;
// using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 gen(228);

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

    vector<int> a(n);
    vector<set<int>> pos(n + 1);

    fori(0, n) {
        cin >> a[i];
        pos[a[i]].insert(i);
    }

    while (q--) {
        int t, x; cin >> t >> x; --x;

        if (t == 1) {
            swap(a[x], a[x + 1]);

            pos[a[x]].erase(x + 1);
            pos[a[x + 1]].erase(x);

            pos[a[x]].insert(x);
            pos[a[x + 1]].insert(x + 1);
        } else {
            set<int> s;

            fori(1, n + 1) {
                if (pos[i].empty()) continue;

                s.insert(*pos[i].begin());
            }

            int cur = 0, last = 0;
            while (!s.empty()) {
                auto it = s.begin();

                if (s.size() > 1 && a[*s.begin()] == last) ++it;

                int v = *it; s.erase(v);

                ++cur;
                if (v == x) break;

                last = a[v];

                it = pos[last].upper_bound(v);
                if (it != pos[last].end()) {
                    s.insert(*it);
                }
            }

            cout << cur << "\n";
        }
    }
}

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

    int tt = 1;
    while (tt--) {
        solve();
        cout << "\n";
    }
}