#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
 
#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pqi priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define printdecimal(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define mod (int)(1e9+7)
#define inf LLONG_MAX
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
#define N (int)(2e6+6)

struct segtree
{
	int size;
	vector<int> values;

	void ini(int n)
	{
		size=1;
		while(size<n)
			size*=2;
		values.assign(2*size,1);
	}

	void set(int i,int v,int cur,int lx,int rx)
	{
		if(rx-lx==1)
		{
			values[cur]=v;
			return;
		}
		int m=(lx+rx)/2;
		if(i<m) set(i,v,2*cur+1,lx,m);
		else set(i,v,2*cur+2,m,rx);
		values[cur]=max(values[2*cur+1],values[2*cur+2]);
	}

	void set(int i,int v)
	{
		set(i,v,0,0,size);
	}

	int cal(int v,int cur,int lx,int rx)
	{
		if(values[cur]<v) return -1;
		if(rx-lx==1) return lx;
		int m=(lx+rx)/2;
		int val=cal(v,2*cur+1,lx,m);
		if(val==-1) return cal(v,2*cur+2,m,rx);
		return val;
	}

	int cal(int v)
	{
		return cal(v,0,0,size);
	}
};


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	for(int i=0;i<100;i++){}
	int n,m;
	cin>>n>>m;
	segtree st;
	st.ini(N);
	inp(a,n,0);
	int h[n+1]={0};
	for(int i=0;i<m-1;i++)
		st.set(a[i],0),h[a[i]]++;
	int ans=inf;
	for(int j=m-1,i=0;j<n;j++,i++)
	{
		if(h[a[j]]==0) st.set(a[j],0);
		h[a[j]]++;
		int idx=st.cal(1);
		ans=min(ans,idx);
		h[a[i]]--;
		if(h[a[i]]==0) st.set(a[i],1);
	}
  for(int i=0;i<100;i++){}
	cout<<ans;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define yes(x) ((x) ? "yes" : "no")
#define Yes(x) ((x) ? "Yes" : "No")

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double_t;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 N, M;
    cin >> N >> M;
    vector<i64> A(N);
    for (auto &e : A) cin >> e;

    set<i64> unused;
    for (i64 i = 0; i < N; i++) unused.insert(i);
    vector<i64> usedcnt(N);
    for (i64 i = 0; i < M; i++) usedcnt[A[i]]++, unused.erase(A[i]);

    i64 ans = unused.empty() ? N : *unused.begin();
    for (i64 i = M; i < N; i++) {
        if (++usedcnt[A[i]] == 1) unused.erase(A[i]);
        if (--usedcnt[A[i - M]] == 0) unused.insert(A[i - M]);
        ans = min(ans, *unused.begin());
    }
    cout << ans << endl;
}

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