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

#define ll long long
ll a[2000000],res[2000000];
int main()
{
    ll n,m,minn;
    cin>>n>>m;
    for(ll i=0;i<n;i++)scanf("%lld",&a[i]);
    for(ll i=0;i<m;i++)
    {
        res[a[i]]++;
    }
    for(ll i=0;;i++)
    {
        if(res[i]==0)
        {
            minn=i;
            break;
        }
    }
    //cout<<minn<<endl;
    ll L=1,R=m;
    for(;R<n;R++,L++)
    {
        res[a[L-1]]--;

        res[a[R]]++;
        //cout<<a[L-1]<<" "<<a[R]<<endl;
        if(res[a[L-1]]==0&&a[L-1]<minn)
        {

            minn=a[L-1];
        }
        if(minn==0)break;
    }
    cout<<minn<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int n, i, j, k, m;
vector<int>v[1500010];
main()
{
    for(scanf("%d %d", &n, &m);i++<n;)scanf("%d", &k),v[k].push_back(i);
    for(i=0;i<=n;i++)
    {
        if(v[i].size()==0||v[i][0]>m||v[i].back()+m-1<n)
        {
            printf("%d", i);return 0;
        }
        for(int j=1;j<v[i].size();j++)
        {
            if(v[i][j]-v[i][j-1]>m)
            {
                printf("%d", i);return 0;
            }
        }
    }
}
