#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  vector<int> cnt(2000000,0);
  ll n,m; cin >> n >> m;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
    cnt[a[i]]++;
  }
  ll ans=inf;
  rep(i,2e6){
    if(cnt[i]==0){
      ans=i;
      break;
    }
  }
  map<ll,vector<ll> > mp;
  rep(i,n){
    mp[a[i]].push_back(i);
  }
  for(auto c:mp)if(c.fi<ans){
    auto v=c.se;
    rep(i,v.size()){
      if(i==0&&v[i]-(-1)>m){
        cout << c.fi << endl;
        return 0;
      }
      if(i==v.size()-1&&n-v[i]>m){
        cout << c.fi << endl;
        return 0;
      }
      if(i!=v.size()-1&&v[i+1]-v[i]>m){
        cout << c.fi << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}
#include<bits/stdc++.h>
using namespace std;
int h[1600000] = { 0 };
int num[1600000] = { 0 };
int main()
{
	
	int n;
	cin >> n;
	int size;
	cin >> size;
	for (int i = 1;i <= n;i++)
	{
		cin >> h[i];
		if (i <= size)num[h[i]]++;
	}
	int mina;
	for (int i = 0;;i++)
	{
		if (num[i] == 0)
		{
			mina = i;
			break;
		}
	}
	for (int i = 2;i <= n - size + 1;i++)
	{
		if (num[h[i - 1]] == 1 && h[i - 1] < mina&&h[i+size-1]!=h[i-1])
		{
			mina = h[i - 1];
		}
		num[h[i - 1]] = 0;
		num[h[i + size - 1]]++;
	}
	cout << mina<< endl;
}
