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

class RangeMexQuery {
   private:
    int n, m;
    vector<array<int, 3> > ptr;
    vector<int> arr, st;
    int update(const int prv, const int id, const int val, const int l,
               const int r) {
        const int cur = (int)ptr.size();
        ptr.push_back({0, 0, id});
        if (r - l == 1) return cur;
        const int mid = (l + r) / 2;
        if (val < mid) {
            const int res = update(ptr[prv][0], id, val, l, mid);
            ptr[cur][0] = res, ptr[cur][1] = ptr[prv][1];
        } else {
            const int res = update(ptr[prv][1], id, val, mid, r);
            ptr[cur][0] = ptr[prv][0], ptr[cur][1] = res;
        }
        ptr[cur][2] = min(ptr[ptr[cur][0]][2], ptr[ptr[cur][1]][2]);
        return cur;
    }
    void preprocessing(const vector<int>& vec) {
        arr[0] = 0;
        for (int i = 0; i < n; ++i)
            arr[2 * i + 1] = vec[i], arr[2 * i + 2] = vec[i] + 1;
        sort(arr.begin(), arr.end());
        arr.erase(unique(arr.begin(), arr.end()), arr.end());
        m = (int)arr.size(), st[0] = 0, ptr.push_back({0, 0, -1});
        for (int i = 0; i < n; ++i) {
            const int val = (int)(lower_bound(arr.begin(), arr.end(), vec[i]) -
                                  arr.begin());
            st[i + 1] = update(st[i], i, val, 0, m);
        }
    }
    int query(const int cur, const int cri, const int l, const int r) {
        if (cur == 0 || r - l == 1) return arr[l];
        const int mid = (l + r) / 2;
        if (ptr[ptr[cur][0]][2] < cri)
            return query(ptr[cur][0], cri, l, mid);
        else
            return query(ptr[cur][1], cri, mid, r);
    }

   public:
    RangeMexQuery(const vector<int>& vec)
        : n((int)vec.size()), arr(2 * n + 1), st(n + 1) {
        preprocessing(vec);
    }
    int query(const int l, const int r) { return query(st[r], l, 0, m); }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    RangeMexQuery rmq(a);

    int ans = 10e8;
    for (int i = 0; i + m - 1 < n; i++) {
        ans = min(ans, rmq.query(i, i + m));
    }

    cout << ans << endl;
}
#include<bits/stdc++.h>
using namespace std;

#define   fi(a,b) for(int i=a;i<b;i++)
#define   fj(a,b) for(int j=a;j<b;j++)
#define   ff first
#define   ss second
#define   ll long long
#define   ld long double
#define   ull unsigned long long
#define   bp(x) __builtin_popcount(x)
#define   pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define   getMax(x) max_element(x.begin(),x.end())
#define   getMin(x) min_element(x.begin(),x.end())
#define   endl "\n"
typedef   vector<int> vi;
typedef   vector< pair<int,int> > vii;
typedef   vector<long long> vl;
typedef   pair<int,int> pii;
typedef   pair<ll,ll> pll;
typedef   vector< pair<ll,ll> > vll;
//int dx[]={1,0,-1,0};
//int dy[]={0,1,0,-1};
//int dx[]={-1,0,1,1,1,0,-1,-1};
//int dy[]={-1,-1,-1,0,1,1,1,0};

void nikal_pehli_fursat_mai(){
    ll n, m;
    cin>>n>>m;
    vl v(n), ans;
    fi(0, n) cin>>v[i];
    set<int>st;
    multiset<int>st1;
    fi(0, m) st1.insert(v[i]);
    fi(0, m+1){
        if(st1.find(i)==st1.end()) st.insert(i);
    }
    ans.push_back(*st.begin());
    int i=0, j=m;
    while(j<n){
        st1.erase(st1.find(v[i]));
        if(st1.find(v[i])==st1.end()) st.insert(v[i]);
        i++;
        st1.insert(v[j]);
        if(st.find(v[j])!=st.end()){
            st.erase(st.find(v[j]));
        }
        j++;
        ans.push_back(*st.begin());
    }
    // pr(ans);
    cout<<(*getMin(ans))<<endl;
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1; 
    // cin>>tc;
    while(tc--){
    nikal_pehli_fursat_mai();
    }
}
