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

int main(void){
    int n,m;
    cin >> n >> m;
    int a[n];
    rep(i,n) cin >> a[i];
    set<int> b;
    map<int,int> c;
    rep(i,1.5*1e6+1){
        b.insert(i);
        c[i]++;
    } 
    rep(i,m){
        c[a[i]]--;
        b.erase(a[i]);
    } 
    int ans = *begin(b);
    for(int i=0;i+m<n;i++){
        c[a[i]]++;
        c[a[i+m]]--;
        if(c[a[i]]>0) b.insert(a[i]);
        if(c[a[i+m]]<=0) b.erase(a[i+m]);
        ans = min(ans,*begin(b));
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

 vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 

clock_t startTime; 
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}   
 

#define PI 3.14159265358979323846
const int maxn = 1500002; 
vector<int> v(maxn), last(maxn);  

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(NULL);  
  int n, m;
  cin >> n >> m; 
  int ans = 987654321;
  for (int i = 1; i <= n; i++) {
    cin >> v[i]; 
    if (i - last[v[i]] > m) {
      ans = min(ans, v[i]); 
    }
    last[v[i]] = i; 
  } 
  for (int i = 0; i <= n; i++) {
    if (n + 1 - last[i] > m) {
      ans = min(ans, i);
    }
  }
  cout << ans << "\n";
  return 0; 
}