#include <bits/stdc++.h>
using namespace std;

////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
//#define mod 9999991
long mod=9999991;
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getline(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(pair<int,int> a,pair<int,int> b){
    double x=(double )a.first/a.second;
    double y=(double )b.first/b.second;
    return x<y;}
long Pow(long x, long y) {
    if(y == 0)return 1;
    long res=Pow(x,y/2)%mod;
    res=(res*res)%mod;
    if(y&1)res=(res*x)%mod;
    return res;
}
#define printcase(x)  cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a,b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
#define esp 1e-9
////////////////////////////////////////////////////////////////////////////</editor-fold>
long t,n,m,f=0,ans,a,b;
long tmp;



int main() {
///<editor-fold desc="ios">
    IOS
#ifdef _AD_
    filein //fileout
#endif
///</editor-fold>
    int in=1,o;
    cin>>n>>m;
    vector<vector<int>> idx(n+1,{0});
    for(int i = 1; i <=n ; ++i){
        cin>>tmp;
        idx[tmp].push_back(i);
    }
    for(int i = 0; i <=n ; ++i){
        idx[i].push_back(n+1);
    }
    for(int i = 0; i <= n; ++i){
        for(int j = 1; j <idx[i].size() ; ++j){
            if(idx[i][j]-idx[i][j-1]-1>=m){
                cout<<i<<endl;
                return 0;
            }
        }
    }







}
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct UnionFind {
    vector<int> par;
	vector<int> cnt;

    UnionFind(int n) : par(n), cnt(n, 1) {
        for (int i = 0; i < n; ++i) { par[i] = i; }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[ry] = rx;
		cnt[rx] += cnt[ry];
    }

	int count(int x) {
		return cnt[root(x)];
	}
};

void solve() {
    ll n, q;
    cin >> n >> q;
    vll c(n);
    rep(i, n) cin >> c[i];
    rep(i, n) --c[i];
    UnionFind uf(n);
    vector<map<ll, ll>> vmp(n);
    rep(i, n) vmp[i][c[i]]++;
    rep(__i, q) {
        ll t, a, b;
        cin >> t >> a >> b;
        --a, --b;
        if(t == 1) {
            if(uf.issame(a, b)) continue;
            if(uf.count(a) < uf.count(b)) swap(a, b);
//            if(vmp[a].size() < vmp[b].size()) swap(a, b);
            ll rt_old = uf.root(b);
            uf.merge(a, b);
            ll rt_new = uf.root(a);
            for(auto i = vmp[rt_old].begin(); i != vmp[rt_old].end(); ++i) {
                vmp[rt_new][i->first] += i->second;
            }
            vmp[rt_old].clear();
        }
        else {
            ll rt = uf.root(a);
            cout << vmp[rt][b] << endl;
        }
    }
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}