#include <iostream>
#include <cstdio>

using namespace std;
using ll = long long;

int main() {
    ll n, m; cin >> n >> m;
    ll array[n], cnt[n] = {0}, ans = n;
    for (ll i = 0; i < n; i++) {
        cin >> array[i];
    }
    for (ll i = 0; i < m; i++) {
        cnt[array[i]]++;
    }
    for (ll i = 0; i < n; i++) {
        if (cnt[i] == 0) {
            ans = i;
            break;
        }
    }
    for (ll i = m; i < n; i++) {
        ll a = array[i];
        ll b = array[i-m];
        cnt[a]++;
        cnt[b]--;
        if (b < ans && cnt[b] == 0) {
            ans = b;
        }
    }
    cout << ans << endl;
    return 0;
}
/*
ID: Trump
TASK: 
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define sll(n) scanf("%lld",&n);
#define sll2(a,b) scanf("%lld",&n);
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c);
#define slb(n) scanf("%Lf",&n);
#define pll(n) printf("%lld",n);
#define pln printf("\n");
#define plb(n) printf("%Lf",n);
#define plb2(n) printf("%.2Lf",n);
#define plb3(n) printf("%.3Lf",n);
#define plb4(n) printf("%.4Lf",n);
#define plb5(n) printf("%.5Lf",n);
#define plb6(n) printf("%.6Lf",n);
using namespace std;
typedef long long ll;
typedef long double lb;
typedef double db;
typedef int it;
typedef bool bl;
//#define MARK
const ll losn=1e6+5;
const ll maxn=1e5+5;
const ll minn=1e3+5;
const ll tiny=1e2+5;
const ll inf=1e9;
const ll binf=1e18;
const ll mod=1e9+7;
const ll lmod=998244353;
const ll hashmod=4698571;
const lb pi=3.1415926;
const ll myn=0;
void gk(){cout<<"---------------"<<endl;}
void ck(){cout<<1<<endl;}
void ck(ll a){cout<<a<<endl;}
void ck(ll a[minn][minn],ll n,ll m){for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++){cout<<a[i][j]<<" ";}cout<<endl;}}
ll n,m,k,T,u,v,len;

ll arr[losn*2];
struct node{
	ll s,nums,as;
};
node tree[losn*2<<4];

void pushup(ll rt){
	if(tree[rt<<1].s<tree[rt<<1|1].s){
		tree[rt]=tree[rt<<1];
	}else{
		tree[rt]=tree[rt<<1|1];
	}
}

void build(ll l,ll r,ll rt){
	ll mid=(l+r)>>1;
	if(l==r){
		tree[rt].s=l;
		tree[rt].nums=0;
		tree[rt].as=0;
		return;
	}
	if(l<r){
		build(l,mid,rt<<1);
		build(mid+1,r,rt<<1|1);
	}
	pushup(rt);
}


void update(ll x,ll c,ll l,ll r,ll rt){
	ll mid=(l+r)>>1;
	if(l==r){
		tree[rt].nums+=c;
		if(tree[rt].nums==0){
			tree[rt].s=l;
		}else{
			tree[rt].s=binf;
		}
		return ;
	}
	if(x<=mid){
		update(x,c,l,mid,rt<<1);
	}
	if(x>mid){
		update(x,c,mid+1,r,rt<<1|1);
	}
	pushup(rt);
}


int main(){
//#ifdef MARK
//    freopen("input.in", "r", stdin);
//    freopen("ouput.out", "w", stdout);
//    freopen("ouput.out", "r", stdin);
//    freopen("input.in", "w", stdout);
//#endif
	cin>>n>>m;
	for(ll i=1;i<=n;i++){
		cin>>arr[i];
		arr[i]+=1;
	}
	build(1,m,1);
	for(ll i=1;i<=m;i++){
		if(arr[i]>=m+1){
			
		}else{
			update(arr[i],1,1,m,1);
		}
	}
	ll l=1,r=m;
	ll ans=binf;
	while(r<=n){
		node q=tree[1];
//		cout<<q.s<<endl;
		if(q.s==binf){
			ans=min(ans,m);
		}else{
			ans=min(ans,q.s-1);
		}
		r++;
		if(arr[r]<=m){
			update(arr[r],1,1,m,1);
		}
		if(arr[l]<=m){
			update(arr[l],-1,1,m,1);
		}
		l++;
		if(r==n+1){
			break;
		}
	}
	ck(ans);
	return 0;
}
/*
0 1 2

2


*/