#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
vector<int>pos[2000006];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, M;
	cin >> N >> M;
	vector<int>A(N);
	rep(i, N + 1) {
		pos[i].push_back(0);
	}
	rep(i, N) {
		cin >> A[i];
		pos[A[i]].push_back(i + 1);
	}
	rep(i, N + 1) {
		pos[i].push_back(N + 1);
	}
	rep(i, N + 1) {
		rep2(j, 1, pos[i].size()) {
			if ((pos[i][j] - pos[i][j - 1]) > M) {
				cout << i << endl;
				return 0;
			}
		}
	}
	return 0;
}
#include<bits/stdc++.h>
using namespace std ;
#define ll long long 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define pii pair<ll,ll> 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
int main()
{
	fast
	int n,m;
	cin>>n>>m;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	map<int,int> mm;
	set<int>s;
	for(int i=0;i<=m;i++)
		s.insert(i);
	for(int i=0;i<m;i++)
		{mm[a[i]]++;if(s.count(a[i]))s.erase(a[i]);}

	int ans=*s.begin();
	for(int i=m;i<n;i++)
	{
		mm[a[i-m]]--;
		mm[a[i]]++;
		if(mm[a[i-m]]==0)
			s.insert(a[i-m]);
		
		ans=min(ans,*s.begin());
	}
	cout<<ans;

	

	return 0;
}