#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M, A;
    cin >> N >> M;
    vector<vector<int>> pos(N + 1);
    for(int i = 0; i <= N; ++i) pos[i].emplace_back(-1);
    for(int i = 0; i < N; ++i){
        cin >> A;
        pos[A].emplace_back(i);
    }
    for(int i = 0; i <= N; ++i) pos[i].emplace_back(N);
    for(int i = 0; i <= N; ++i){
        for(int j = 0; j + 1 < (int)pos[i].size(); ++j){
            if(pos[i][j + 1] - pos[i][j] > M){
                cout << i << '\n';
                return 0;
            }
        }
    }

    return 0;
}
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
using ll = long long;

map<ll, ll> freq;
set<ll> mex;
int n, m;

int main(){

    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(ll i = 0; i <= n; ++i)
        mex.insert(i);

    vector<ll> vec(n);
    for(auto & el: vec)
        cin >> el;

    for(int i = 0; i < m; ++i){
        freq[vec[i]]++;
        mex.erase(vec[i]);
    }

    ll res = *mex.begin();
    for(int i = m; i < n; ++i){
        freq[vec[i - m]]--;
        if(freq[vec[i - m]] == 0 ){
            mex.insert(vec[i - m]);
            freq.erase(vec[i - m]);
        }

        freq[vec[i]]++;
        if(freq[vec[i]] == 1)
            mex.erase(vec[i]);
        
        res = min(res, * mex.begin());
    }

    cout << res;
}
