#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pw(x) ((1LL)<<(x))
#define sz(x) (ll)x.size()
#define all(x) x.begin(), x.end()

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

using namespace std;

const ll N = 5e5 + 52;
const ll INF = 1e18;
const ll MOD = 998244353;

ll n, m;
ll i, j;
ll a[N];
string s;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // LOCAL
    ll q;
    cin >> n >> q;
    map<ll,vector<ll>> p;
    for (i=1;i<=n;i++){
        cin >> a[i];
    }
    for (i=n;i>=1;i--){
        p[a[i]].pb(i);
    }
    while(q--){
        ll type;
        cin >> type;
        if (type==1){
            ll pos, pos1;
            cin >> pos;
            pos1 = pos+1;
            swap(a[pos],a[pos1]);
        }else{
            ll x;
            cin >> x;
            set<pair<ll,ll>> b;
            for (auto [x,v] : p){
                b.insert({v.back(),x});
            }
            ll last = -1;
            ll kol=0;
            while(true){
                kol++;
                auto it = b.begin();
                if (sz(b)!=1){
                    if (it->se==last) ++it;
                }
                last = it->se;
//                cout << "last=" << last << " " << it->fi << endl;
                if (it->fi==x){
                    cout << kol << endl;
                    break;
                }
                p[last].ppb();
                if (!p[last].empty()){
                    b.insert({p[last].back(),last});
                }
                b.erase(it);
            }
        }
        p.clear();
        for (i=n;i>=1;i--){
            p[a[i]].pb(i);
        }
    }
    return 0;
}
