#include "iostream"
using namespace std;
//#include "string"
#include "vector"
#include "set"
#include "map"
#include "stack"
#include "algorithm"
#include "queue"
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl '\n'
#define vi vector<int>

int32_t main() {
	boost;
	int n, m;
	cin >> n >> m;
	vi a(n);
	for(int &i : a)
		cin >> i;
	set<pi> s;
	for(int i = 0; i <= n; i++)
		s.insert(make_pair(0, i));
	vi f(n + 1, 0);
	int ans = n;
	for(int i = 0; i < n; i++) {
		s.erase(make_pair(f[a[i]], a[i]));
		f[a[i]]++;
		s.insert(make_pair(f[a[i]], a[i]));

		if(i >= m - 1) {
			ans = min(ans, s.begin() -> ss);
			s.erase(make_pair(f[a[i - m + 1]], a[i - m + 1]));
			f[a[i - m + 1]]--;
			s.insert(make_pair(f[a[i - m + 1]], a[i - m + 1]));
		}
	}
	cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;

int main() {
    int N,M; cin>>N>>M;
    vvi pos(N, {-1});
    for (int i = 0; i < N; i++){
        int A; cin>>A;
        pos[A].push_back(i);
    }
    for (int i = 0; i < N; i++)pos[i].push_back(N);

    for (int i = 0; i < N; i++){
        for (int j = 0; j < pos[i].size()-1; j++){
            if(pos[i][j+1]-pos[i][j]-1>=M){
                cout<<i<<endl;
                return 0;
            }
        }
    }
    cout<<N<<endl;
}