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

using ll=long long;
ll mod=1000000007;

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> P(N);
    for(int i=0;i<N;i++){
        int A;
        cin >> A;
        P[A].push_back(i);
    }
    for(int i=0;i<N;i++){
        int prev=-1;
        P[i].push_back(N);
        for(int j:P[i]){
            if(j-prev>M){
                cout << i << endl;
                return 0;
            }
            prev=j;
        }
    }
    cout << N << endl;
}
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6;
typedef long long ll;
template<class T> T read()
{
	T f = 1, k = 0;
	char c = getchar();
	while (c < '0' || c > '9')
	{
		if (c == '-')
			f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		k = k * 10 + c - '0';
		c = getchar();
	}
	return f * k;
}

int n, m, a[maxn];
vector<int> v[maxn];
int main()
{
	n = read<int>();
	m = read<int>();
	for (int i = 1; i <= n; i++)
	{
		a[i] = read<int>();
		v[a[i]].emplace_back(i);
	}
	for (int i = 0; i < maxn; i++)
	{
		if ((int)v[i].size() == 0)
			return printf("%d\n", i), 0;
		for (int j = 0; j < (int)v[i].size(); j++)
		{
			if (j == 0 && v[i][j] > m)
				return printf("%d\n", i), 0;
			if (j != 0 && v[i][j] - v[i][j - 1] - 1 >= m)
				return printf("%d\n", i), 0;
			if (j == (int)v[i].size() - 1 && n - v[i][j] >= m)
				return printf("%d\n", i), 0;
		}
	}
}
