#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,f[1500009],pas;
multiset <int> s,h;
multiset <int>::iterator it,tt;
void ins(int q){
	it=h.lower_bound(q);
	if(it!=h.end()&&(*it)==q){
		h.erase(it);
	}
	s.insert(q);
}
void er(int q){
	it=s.lower_bound(q);
	s.erase(it);
	it=s.lower_bound(q);
	if(it!=s.end()&&(*it)==q){
		
	}else{
		h.insert(q);
	}
}
void chk(){
	tt=h.begin();
	if(pas>(*tt)) pas=(*tt);
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>b;
	pas=a+2;
	for(i=1; i<=a; i++){
		cin>>f[i];
	}
	for(i=0; i<=a+2; i++){
		h.insert(i);
	}
	for(i=1; i<=b; i++){
		//s.insert(f[i]);
		ins(f[i]);
	}
	chk();
	for(i=b+1; i<=a; i++){
		c=f[i-b];
		/*it=s.lower_bound(c);
		s.erase(it);*/
		er(c);
		//s.insert(f[i]);
		ins(f[i]);
		chk();
	}
	cout<<pas;
	return 0;
}
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
#define int long long  
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
  b%=m;
  ll ans = 1;
  for (; e; b = b * b % m, e /= 2)
      if (e & 1) ans = ans * b % m;
  return ans;
}

const int N = 1511111 + 100;
int tree[N*4];
int qtd[N*4];
void upd(int no,int i,int j,int p,int v){
  if(i==j){
    qtd[no]+=v;
    tree[no] = (qtd[no] ? 1 : 0);
    return;
  }
  int mid = (i+j)>>1;
  int l=no<<1,r=no<<1|1;
  if(p<=mid)upd(l,i,mid,p,v);
  else upd(r,mid+1,j,p,v);
  tree[no] = tree[l] + tree[r];
}

int query(int no,int i,int j){
  if(i==j)return i;
  int mid = (i+j)>>1;
  int l=no<<1,r=no<<1|1;
  if(tree[l]!=(mid - i + 1)){
    return query(l,i,mid);
  }
  return query(r,mid+1,j);
}
int a[N];

int32_t main(){
  fastio;
  int n,m;
  cin >> n >> m;
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }

  for(int i=1;i<=m;i++){
    upd(1,0,n,a[i],1);
  }
  int res = 1e9;
  for(int i=m;i<=n;i++){
    if(i!=m){
      upd(1,0,n,a[i-m],-1);
      upd(1,0,n,a[i],1);
    }
    res = min(res,query(1,0,n));
  }

  cout << res << endl;

  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}