//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
#define sz(x) int(x.size())
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template<typename T> void print(T a) {cout << a << ' ';}
template<typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template<typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n, m; cin >> n >> m;
    V<V<int>> p(n);
    rep(i, n) p[i].emplace_back(0);
    rep(i, n) {
        int a; cin >> a;
        p[a].emplace_back(i+1);
    }
    rep(i, n) p[i].emplace_back(n+1);
    V<int> d(n, 0);
    rep(i, n) {
        rep(j, sz(p[i])-1) chmax(d[i], p[i][j+1] - p[i][j]);
    }
    int ans = n;
    rep(i, n) {
        if (d[i] >= m+1) chmin(ans, i);
    }
    cout << ans << endl;

    return 0;
}
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=2000010; //check the limits, dummy
int a[N];
int n, m;
vector<int> pos[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0; i<=n; ++i){
		pos[i].push_back(-1);
	}
	for(int i=0; i<n; ++i){
		scanf("%d",a+i);
		pos[a[i]].push_back(i);
	}
	int ans = -1;
	for(int i=0;i<=n; ++i){
		pos[i].push_back(n);
		for(int j=0; j+1<pos[i].size(); ++j){
			if(pos[i][j+1]-pos[i][j]-1>=m){
				ans = i;
				break;
			}
		}
		if(ans!=-1)break;
	}
	cout<<ans<<endl;
}