#include <bits/stdc++.h>

#pragma GCC optymize("o3")
#pragma GCC target("avx2")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main()
{
    int n, q;
    cin >> n >> q;

    vi a(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    vector<multiset<int>> vis(n + 1);
    for (int j = 1; j <= n; ++j)
    {
        for (int i = 1; i <= n; ++i)
        {
            if (a[i] != j)
                vis[j].insert(i);
        }
    }

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

        if (t == 1)
        {
            for (int j = 1; j <= n; ++j)
            {
                if (j == a[xy])
                    continue;
                bool flag = false;
                if (vis[j].count(xy) > 1)
                    flag = true;
                vis[j].erase(xy);
                if (flag)
                    vis[j].insert(xy);
                vis[j].insert(xy + 1);
            }
            for (int j = 1; j <= n; ++j)
            {
                if (j == a[xy + 1])
                    continue;
                bool flag = false;
                if (vis[j].count(xy + 1) > 1)
                    flag = true;
                vis[j].erase(xy + 1);
                if (flag)
                    vis[j].insert(xy + 1);
                vis[j].insert(xy);
            }
            swap(a[xy], a[xy + 1]);
        }
        else
        {
            vector<multiset<int>> viss = vis;
            int last = 1, ans = 1, help;
            for (int j = 1; j <= n; ++j)
            {
                if (j != a[last])
                    viss[j].erase(last);
            }
            while (last != xy)
            {
                help = last;
                last = *viss[a[last]].begin();
                if (last == 0)
                {
                    for (int i = help; i < xy; ++i)
                    {
                        if (a[i] == a[help])
                            ans++;
                    }
                    break;
                }
                for (int j = 1; j <= n; ++j)
                {
                    if (j != a[last])
                        viss[j].erase(last);
                }
                ans++;
            }
            cout << ans << '\n';
        }
    }
}

/*#include <bits/stdc++.h>

#define int long long

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int32_t main()
{
    int n, q;
    cin >> n >> q;

    vi a(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    vvi cnt(6, vi(n + 1));
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j < 6; ++j)
        {
            if (a[i] == j)
                cnt[j][i] = 1 + cnt[j][i - 1];
            else
                cnt[j][i] = cnt[j][i - 1];
        }
    }

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

        if (t == 1)
        {
            swap(a[xy], a[xy + 1]);
            if (a[xy] == a[xy + 1])
                continue;
            
            cnt[a[xy]][xy]++;
            cnt[a[xy + 1]][xy]--;
        }
        else
        {
            for (int j = 1; j < 6; ++j)
            {
                if (a[xy] != j)
                    continue;
                
                if (a[1] == j)
                    cout << cnt[j][xy] + min(cnt[j][xy] - 1, S) << '\n';\
                else
                    cout << cnt[j][xy] + min();
            }


            if (a[1] == 1)
            {
                if (a[xy] == 1)
                    cout << cnt1[xy] + min(cnt1[xy] - 1, cnt2[n]) << '\n';
                else
                    cout << cnt2[xy] + min(cnt2[xy], cnt1[n]) << '\n';
            }
            else
            {
                if (a[xy] == 1)
                    cout << cnt1[xy] + min(cnt1[xy], cnt2[n]) << '\n';
                else
                    cout << cnt2[xy] + min(cnt2[xy] - 1, cnt1[n]) << '\n';
            }
        }
    }
}*/