#include <bits/stdc++.h>

using namespace std;


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    int a[n];
    for(int i = 0;i < n;++i)
    {
        cin >> a[i];
    }
    while(q--)
    {
        int t;
        cin >> t;
        if(t == 1)
        {
            int x;
            cin >> x;
            x--;
            swap(a[x],a[x+1]);
        }
        else
        {
            int y;
            cin >> y;
            y--;
            vector<pair<int,int>> f,s;
            f.push_back({-1,-1});
            s.push_back({-1,-1});
            for(int j = 0;j < n;++j)
            {
                if(a[j] != f.back().first && a[j] != s.back().first)
                {
                    if(f.size() <= s.size())
                    {
                        f.push_back({a[j],j});
                    }
                    else
                        s.push_back({a[j],j});
                }
                else if(a[j] == f.back().first)
                {
                    f.push_back({a[j],j});
                }
                else
                {
                    s.push_back({a[j],j});
                }
            }
            int ans = -1;
            for(int j = 0;j < f.size();++j)
            {
                if(f[j].second == y)
                {
                    ans = min(j * 2,int(n + 1 - (f.size() - j - 1)));
                }
            }
            for(int j = 0;j < s.size();++j)
            {
                if(s[j].second == y)
                {
                    ans = min(j * 2 + 1,int(n + 1 - (s.size() -j - 1)));
                }
            }
            cout << ans - 1 << "\n";
        }
    }
}