#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int N = 1500000;

int aa[N];
vector<int> ii[N];

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> aa[i];
	for (int i = 0; i < n; i++)
		ii[aa[i]].push_back(i);
	for (int a = 0; a < n; a++) {
		int i_ = -1;
		for (int i : ii[a]) {
			if (i - i_ - 1 >= m) {
				cout << a << '\n';
				return 0;
			}
			i_ = i;
		}
		if (n - i_ - 1 >= m) {
			cout << a << '\n';
			return 0;
		}
	}
	cout << n << '\n';
	return 0;
}

#include <stdio.h>
#include <assert.h>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <vector>
#include <numeric>
#include <iomanip>
#define ll long long
#define mint modint<MOD>
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tpiii tuple<int,int,int>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector
#define vi vec<int>
#define vmi vec<mint>
#define vl vec<ll>
#define vvi vec<vi>
#define vvl vec<vl>
#define vpii vec<pii>
#define vpll vec<pll>
#define vbl vec<bool>
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
char chin(){char c;cin>>c;return c;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void drop(string s){cout<<s<<endl; exit(0);}
void drop(int x){cout<<x<<endl; exit(0);}
void drop(ll x){cout<<x<<endl; exit(0);}
void drop(double x){cout<<x<<endl; exit(0);}

int main(){
    int n=in(),m=in();
    vi a(n),cnt(n,0);
    rep(i,n)a[i]=in();
    rep(i,m)cnt[a[i]]++;
    int ans=n;
    rep(i,n)if(cnt[i]==0){
        ans=i;
        break;
    }
    rep(i,n-m){
        cnt[a[i]]--;
        cnt[a[i+m]]++;
        if(cnt[a[i]]==0)chmin(ans,a[i]);
    }
    drop(ans);
}