#include "bits/stdc++.h"
#include<sstream>
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const long long inf = 1e18;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;

int digit(ll x) {
    int digits = 0;
 
    while(x > 0){
        x /= 10;
        digits++;
    }
 
    return digits;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}
 
bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
long long modpow(long long a, long long b, long long m){
    long long ans = 1;
    while(b > 0){
        if (b % 2 == 1){
            ans *= a;
            ans %= m;
        }
        a *= a;
        a %= m;
        b /= 2;
    }
    return ans;
}

long long comb(long long x, long long y){
    int z;
    if (y == 0) return 1;
    else {
        z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD;
        if (y % 2 == 1) z = z*x%MOD;
        return z;
    }
}

vector<long long> fact(long long x){
    vector<long long> res;
    for(int i = 1;i*i <= x;i++){
        if (x % i == 0){
            res.push_back(i);
            res.push_back(x / i);
        }
    }

    return res;
}

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

vector<pair<long long, long long>> prime_fact(long long x){
    vector<pair<long long, long long>> res;
    for(int i = 2;i*i <= x;i++){
        if (x % i == 0){
            long long cnt = 0;
            while(x % i == 0){
                cnt++;
                x /= i;
            }
            res.push_back({i, cnt});
        }
    }
    if (x != 1){
        res.push_back({x, 1});
    }
    return res;
}

int64_t mod_inv(int64_t a, int64_t m){
    int64_t b = m, u = 1, v = 0;

    while(b){
        int64_t t = a/b;
        a -= t*b;
        swap(a, b);
        u -= t*v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;

    return u;
}


// {g, x, y}: ax + by = g
tuple<long long, long long, long long> extgcd(long long a, long long b){
    if (b == 0) return {a, 1, 0};
    long long g, x, y;
    tie(g, x, y) = extgcd(b, a % b);
    return {g, y, x - a/b*y};
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

//////////////////////////

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    set<int> st;
    for(int i = 0;i <= n;i++){
        st.insert(i);
    }

    int ans = n;
    vector<int> cnt(n, 0);
    for(int i = 0;i < m;i++){
        cnt[a[i]]++;
        if (cnt[a[i]] == 1) st.erase(a[i]);
    }
    ans = min(ans, *st.begin());
    for(int i = m;i < n;i++){
        cnt[a[i]]++;
        cnt[a[i - m]]--;
        if (a[i] != a[i - m]){
            if (cnt[a[i]] == 1) st.erase(a[i]);
            if (cnt[a[i - m]] == 0) st.insert(a[i - m]);
        }
        ans = min(ans, *st.begin());
    }

    cout << ans << endl;
}

#include<bits/stdc++.h>
// 数値型
using ll= long long;
using ull= unsigned long long;
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define FORB(i,I) for(auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e18
#define PI 3.141592653589
// #define MOD 1000000007 //問題による
// #define MOD (int)1e9+7 //10^9+7:合同式の法
//略記
#define FS first
#define SC second
#define PB push_back
#define Graph vector<vector<ll>>
#define Pll2 pair<ll,ll>
#define Vll vector<ll>
#define VVll vector<vector<ll>>
#define VPll2 vector<pair<ll,ll>>
#define DDD fixed<<setprecision(10)
//出力(空白区切りで昇順に)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define coutALL(x) for(auto iii=x.begin();iii!=--x.end();iii++)cout<<*iii<<" ";cout<<*--x.end()<<endl;
#define coutline cout<<"======================================================="<<endl;
#define coutlinec(x) cout<<string(55, x)<<endl;
//その他
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);
using namespace std;


#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/
#define sqr(x)  ((x) * (x)) // xの二乗値を求める
#define cub(x)  ((x) * (x) * (x)) // xの三乗値を求める
//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}



/*.........................MAIN...........................*/
signed main() {
    //小数の桁数の出力指定
    //cout<<fixed<<setprecision(10);
    __MAGIC__
    //
    ll N, M;
    cin >> N >> M;
    //
    ll sz = N+1;
    VVll pos(sz, Vll(1, -1));
    REP(i, N) {
        ll a; cin >> a;
        pos[a].PB(i);
    }
    //
    REP(i, sz){ pos[i].PB(N); }
    //
    REP(i, sz) {
        ll pos_size = SIZE(pos[i]);
        // coutALL(pos[i]);
        REP(j, pos_size-1) {
            if ((pos[i][j+1] - pos[i][j]) > M) {
                cout << i << endl;
                return 0;
            }
        }
    }

    //
    return 0;
}