#include "bits/extc++.h"
//#pragma optimize("O3")
//#pragma target("avx2,popcnt")
//#pragma target("unroll-loops")
using namespace std;
using namespace __gnu_pbds;
using ll = long long;

using ordered_set = tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &v: a) is >> v;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, vector<T> &a) {
    for (auto &v: a) os << v << " ";
    return (os << "\n");
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#endif

    int n, Q;
    cin >> n >> Q;

    vector<int> a(n);
    cin >> a;

    for (int i = 0; i < n; ++i) {
        a[i]--;
    }

    vector<pair<int, int>> segs;
    for (int i = 0; i < n;) {
        int cnt = 0;
        while (i + cnt < n && a[i] == a[i + cnt]) cnt++;
        segs.push_back({i, i + cnt});
        i += cnt;
    }

    while (Q--) {
        int t;
        cin >> t;

        if (t == 1) {
            int ind;
            cin >> ind;

            swap(a[ind - 1], a[ind]);

            segs.clear();
            for (int i = 0; i < n;) {
                int cnt = 0;
                while (i + cnt < n && a[i] == a[i + cnt]) cnt++;
                segs.push_back({i, i + cnt});
                i += cnt;
            }

            continue;
        }

        int x;
        cin >> x;
        x--;

        deque<pair<int, int>> q;

        int cnt = 0;
        int last = -1;
        for (int i = 0; i < segs.size(); ++i) {
            if (q.empty() || a[q.front().first] == a[segs[i].first]) {
                q.push_back(segs[i]);
                continue;
            }

            int szr = segs[i].second - segs[i].first;
            int szl = q.front().second - q.front().first;

            if (szr >= szl) {
                if (q.front().first <= x && x < q.front().second){
                    if (last == a[q.front().first]){
                        cout << cnt + (x-q.front().first) * 2 + 2 << "\n";
                    } else {
                        cout << cnt + (x-q.front().first) * 2 + 1 << "\n";
                    }
                }


                if (segs[i].first <= x && x < segs[i].first + szl){
                    if (last == a[q.front().first]){
                        cout << cnt + (x-segs[i].first) * 2 + 1 << "\n";
                    } else {
                        cout << cnt + (x-segs[i].first) * 2 + 2 << "\n";
                    }
                }

                if (last == a[q.front().first]){
                    last =  a[q.front().first];
                } else {
                    last = a[segs[i].first];
                }

                cnt += 2 * szl;

                q.pop_front();
                q.push_back(segs[i]);
                q.back().first += szl;
            } else {
                if (q.front().first <= x && x < q.front().first + szr){
                    if (last == a[q.front().first]){
                        cout << cnt + (x-q.front().first) * 2 + 2 << "\n";
                    } else {
                        cout << cnt + (x-q.front().first) * 2 + 1 << "\n";
                    }
                }
                if (segs[i].first <= x && x < segs[i].second){
                    if (last == a[q.front().first]){
                        cout << cnt + (x-segs[i].first) * 2 + 1 << "\n";
                    } else {
                        cout << cnt + (x-segs[i].first) * 2 + 2 << "\n";
                    }
                }

                if (last == a[q.front().first]){
                    last =  a[q.front().first];
                } else {
                    last = a[segs[i].first];
                }


                cnt += 2 * szr;
                q.front().first += szr;
            }
        }

        for (auto [l,r]: q){
            if (l <= x && x < r){
                cout << cnt + x-l + 1 << "\n";
            }
            cnt += r-l;
        }
    }
}