#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdexcept>
#include<math.h>
using namespace std;


using ll=long long ;

#define rep(i,n)  for(int i=0;i<(n);i++)
#define f first
#define sc second


int fact(int n){
if(n==0){
     return 1;
 }else{
     return n*fact(n-1);
 }
}

bool is_prime(int x){
if(x<=1) return false;
for(int i=2;i*i<x;i++){
    if(x%i==0) return false;}
return true;}

template<class T>void chmin(T& a,T b){
    if(a>b){
        a=b;
    }
}

template<class T>void chmax(T& a,T b){
    if(a<b){
        a=b;
    }
}
int gcd(int x, int y) {
     if(x % y == 0) {
        return y;
     } else {
        return gcd(y, x % y); 
     }
}

ll f(ll x,ll c,ll d){
    return x-x/c-x/d+x/(c/(gcd(c,d))*d);
}



string to_oct(int n){
    string s;
    while(n){
     s = std::to_string(n%8) + s;
     n /= 8;
    }
return s;
}


using namespace std;
int main(){
   ll n,m;
   cin>>n>>m;

   ll a[n];
   set<ll> d;
   rep(i,n+1)d.insert(i);

   ll mex=n;
   map<ll,int> mp;

   rep(i,n)cin>>a[i];

   rep(i,m){
       mp[a[i]]++;
       d.erase(a[i]);
   }

   mex=*begin(d);
   int j=0;

   for(int i=m; i<=n-1;i++){
       mp[a[i]]++;
       d.erase(a[i]);
       mp[a[j]]--;
       if(mp[a[j]]==0)d.insert(a[j]);
       mex=min<ll>(mex,*begin(d));
       j++;

   }


   cout << mex << endl;





}
// Problem: E - Mex Min
// Contest: AtCoder - AtCoder Beginner Contest 194
// URL: https://atcoder.jp/contests/abc194/tasks/abc194_e
// Memory Limit: 1024 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)

// krishrawat

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define pb insert
#define eb emplace_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define show(x) cerr << #x << " is " << x << "\n"
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> pp;
typedef vector<pp> vp;
typedef map<ll, ll> ii;
typedef set<ll> sl;
typedef multiset<ll> msl;
typedef set<pair<ll, ll>> sp;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 1;
ll mod_mul(ll x, ll y) { return ((x % MOD) * (y % MOD)) % MOD; }
ll mod_add(ll x, ll y) { return ((x % MOD) + (y % MOD)) % MOD; }

// main code
void solve() {
  ll n, m;
  cin >> n >> m;
  vl v(n);
  for (auto &i : v) cin >> i;
  sl s;
  for (int i = 0; i <= m; i++) s.pb(i);
  ll ans = 1e18;
  ii mp;
  for (int i = 0; i < m; i++) {
    auto it = s.find(v[i]);
    mp[v[i]]++;
    if (it != s.end()) s.erase(it);
  }
  auto it = s.lower_bound(0);
  ans = *it;
  for (int i = m; i < n; i++) {
    mp[v[i - m]]--;
    if (v[i - m] < m && !mp[v[i - m]]) s.pb(v[i - m]);
    it = s.find(v[i]);
    mp[v[i]]++;
    if (it != s.end()) s.erase(it);
    auto it = s.lower_bound(0);
    ans = min(ans, *it);
  }
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t;
  t = 1;
  // cin >> t;
  while (t--) solve();
  return 0;
}
