#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<ll>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< ll, ll> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define prll(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll n, m;
	cin>>n>>m;
	vlli a(n), b(n+2, 0);
	scan(a, 0, n);
	forn(i, 0, m){
		b[a[i]]++;
	}
	ll ans = inf;
	set<ll> p;
	forn(i, 0, n+2){
		if(!b[i]){
			ans = min(ans, i);
			p.insert(i);
		}
	}
	forn(i, m, n){
		b[a[i-m]]--, b[a[i]]++;
		if(b[a[i-m]]==0){
			p.insert(a[i-m]);
		}
		if(b[a[i]]==1){
			p.erase(a[i]);
		}
		auto it = p.begin();
		ans = min(ans, *it);
	}
	cout<<ans<<endl;
}

// Problem: E - Mex Min
// Contest: AtCoder - AtCoder Beginner Contest 194
// URL: https://atcoder.jp/contests/abc194/tasks/abc194_e
// Memory Limit: 1024 MB
// Time Limit: 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)	
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)

const int N = 2e6+7;
int a[N],cnt[N];

int main() 
{
	int n,m;scanf("%d%d",&n,&m);
	forn(i,1,n)	scanf("%d",&a[i]);
	int mex = 0,res = 0;
	forn(i,1,m)	++cnt[a[i]];
	while(cnt[mex])	++mex;
	res = mex;
	
	forn(i,1,n - m)
	{
		--cnt[a[i]];
		++cnt[a[i + m]];
		if(cnt[a[i]] == 0 && mex > a[i])	mex = a[i];
		else	while(cnt[mex])	++mex;
		res = min(res,mex);
	}
	printf("%d\n",res);
	return 0;
}