#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define cases() ll t;cin>>t;while(t--)
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 2e6+5;
const ll INF = 1e18;
const ll MOD = 1e9+7;

vector<int> a[MAX];

int main()
{
    int i,j,k,l,p,q,x,y,n,m;
    cin >> n >> m;
    for(i=0;i<=n;i++)
        a[i].push_back(0);
    for(i=1;i<=n;i++)
    {
        cin >> l;
        a[l].push_back(i);
    }
    for(i=0;i<=n;i++)
        a[i].push_back(n+1);
    for(i=0;i<=n;i++)
    {
        for(j=0;j+1<a[i].size();j++)
        {
            if(a[i][j+1]-a[i][j]>m)
            {
                cout << i;
                return 0;
            }
        }
    }
}
#include<bits/stdc++.h>

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define Bye return 0
#define CodeTyper main
#define ll int long long

using namespace std;
int const max_size = 1.5e6+1;
int freq[max_size];

void solve() {
    int n, m; cin>>n>>m;

    set<int> s;
    for (int i = 0; i<=max_size; i++)
        s.insert(i);

    memset(freq, 0, sizeof freq);

    int a[n];
    for (int i = 0; i<n; i++)
        cin>>a[i];

    for (int i = 0; i<m; i++){
        s.erase(a[i]);
        freq[a[i]]++;
    }

    int mex = min(*s.begin(), max_size);

    for (int i = m; i<n; i++){
        int l = i - m;

        freq[a[l]]--;
        freq[a[i]]++;

        s.erase(a[i]);

        if(freq[a[l]] <= 0)
            s.insert(a[l]);

        mex = min(mex, *(s.begin()));
    }

    cout<<mex<<endl;
}

int CodeTyper()
{
    boost;
    solve();
    Bye;
}

/*
    'Think FIRST, then CODE.'
    'May the CODE be with YOU.'
    'We are PROGRAMMERS, we have NO LIFE!'
*/
