#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>a(n+2);
  a[0]=0;
  a[n+1]=0;
  int maxa=0;
  rep(i,n){
    cin>>a[i+1];
    maxa=max(maxa,a[i+1]);
  }
  set<int>is[maxa+2];
  rep(i,n+2){
    is[a[i]].insert(i);
  }
  
  rep(i,maxa+2){
    if(is[i].size() ==0){
      cout<<i<<endl;
      return 0;
    }
    int temp=0;
    for(auto e=is[i].begin();e != is[i].end();e++){
      if(*e-temp>m){
        cout<<i<<endl;
        return 0;
      }
      else{
        temp=*e;
      }
    }
    if(n-temp>=m){
      cout<<i<<endl;
      return 0;
    }
    
  }
  return 0;
}

      
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf LLONG_MAX
#define int long long
#define mod 998244353

int a[1500005];
int x[1500005];

signed main(void)
{
	int n, m; cin >> n >> m;
	rep (i, n) cin >> a[i];
	set<int> s;
	rep (i, n+1) s.insert(i);
	rep (i, m)
	{
		x[a[i]]++;
		if (x[a[i]] == 1) s.erase(a[i]);
	}
	int ans;
	ans = min(n, *(s.begin()));
	reps (i, m, n)
	{
		x[a[i-m]]--;
		x[a[i]]++;
		if (a[i-m] != a[i])
		{
			if (x[a[i-m]] == 0) s.insert(a[i-m]);
			if (x[a[i]] == 1) s.erase(a[i]);
		}
		ans = min(ans, *(s.begin()));
	}
	cout << ans << endl;
}
