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

using namespace __gnu_pbds;
using namespace std;

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

#define int long long

const int mod = 998244353 , mod2 = 1e9 + 13;

int umn(int a , int b) {
    return ((a * b) % mod + mod) % mod;
}
int add(int a , int b) {
    return ((a + b) % mod + mod) % mod;
}
int umn2(int a , int b) {
    return ((a * b) % mod2 + mod2) % mod2;
}
int mn(int a , int b) {
    return ((a - b) % mod + mod) % mod;
}

int bp(int a , int p) {
    if(p == 0)return 1;
    if(p % 2 == 0) {
        int x = bp(a , p / 2);
        return umn(x , x);
    } else {
        return umn(bp(a , p - 1) , a);
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n , q;    cin >> n >> q;
    vector<int> a(n);
    vector<ordered_set<int>> v(6);
    for(int i = 0 ; i < n ; i++) {
        cin >> a[i];
        a[i]--;
        v[a[i]].insert(i);
    }

    for(int i = 0 ; i < q ; i++) {
        int t;
        cin >> t;
        if(t == 1) {
            int x , y;
            cin >> x;
            x--;
            y--;
            if(a[x] != a[x + 1]) {
                v[a[x]].erase(x);
                v[a[x + 1]].erase(x + 1);
                v[a[x + 1]].insert(x);
                v[a[x]].insert(x + 1);
            }
            swap(a[x] , a[x + 1]);
        } else {
            int x;
            cin >> x;
            x--;
            if(a[0] == a[x]) {
                int id = v[a[x]].order_of_key(x);
                if(v[!a[x]].order_of_key(x) <= id) {
                    cout << id * 2 + id -v[!a[x]].order_of_key(x) + 1 << '\n';
                } else {
                    cout << id * 2  + 1 << '\n';
                }
            } else {
                int id = v[a[x]].order_of_key(x);
                if(v[!a[x]].order_of_key(x) <= id) {
                    cout << id * 2 + id -v[!a[x]].order_of_key(x) << '\n';
                } else {
                    cout << id * 2  << '\n';
                }

            }
        }
    }

}
