#include<bits/stdc++.h>

using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int m, n;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<int> used(n);
    set<int> unused;
    for(int i = 0; i <= n; i++){
        unused.insert(i);
    }
    for(int i = 0; i < m; i++){
        used[a[i]]++;
        if(used[a[i]] == 1){
            unused.erase(a[i]);
        }
    }
    int mem = *unused.begin();
    for(int i = m; i < n; i++){
        used[a[i - m]]--;
        if(used[a[i - m]] == 0){
            unused.insert(a[i - m]);
        }
        used[a[i]]++;
        if(used[a[i]] == 1){
            unused.erase(a[i]);
        }
        mem = min(mem, *unused.begin());
    }
    cout << mem << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned ll
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vs vector<string>
#define vvi vector<vi>
#define ff first
#define ss second
#define pb push_back
#define vpi vector<pi>
#define vpll vector<pll>
#define umap unordered_map
#define uset unordered_set
#define all(x) x.begin(),x.end()
#define fr(i,j,n) for(int i=j;i<n;++i)
#define rfr(i,j,n) for(int i=j; i>=n;--i)
#define MOD 1000000007
#define INF INT_MAX
#define LINF LONG_LONG_MAX  
#define mp make_pair
#define endl "\n"
#define sz  size()
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){
    int n,m;
    cin>>n>>m;
    vi arr(n);
    vvi pos(n+1);
    fr(i,0,n+1){
        // cin>>arr[i-1];
        pos[i].pb(-1);
    }
    fr(i,0,n){
        cin>>arr[i];
        pos[arr[i]].pb(i);
    }
    fr(i,0,n+1){
        // cin>>arr[i-1];
        pos[i].pb(n);
    }
    fr(i,0,n+1){
        fr(j,1,pos[i].sz){
            if(pos[i][j]-pos[i][j-1]>m){
                cout<<i<<endl;
                return;
            }
        }
    }

}

void pre() {
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
        // cout<<solve()<<endl;
    }
}

int main() {
	fastIO; 
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	pre();
	return 0; 
	
}
