    #include <bits/stdc++.h>

    // #include <ext/pb_ds/assoc_container.hpp>
    // #include <ext/rope>
    // #include <ext/pb_ds/tree_policy.hpp>
    // #include <ext/pb_ds/trie_policy.hpp>
    // using namespace __gnu_pbds;
    // using namespace __gnu_cxx;
    // typedef tree<long long, null_type, std::less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
    // typedef trie<std::string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>Trie;

    using namespace std;
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=n-1;i>=a;i--)
    #define pb push_back
    #define mp make_pair
    #define all(x) (x).begin(),(x).end()
    #define fi first
    #define se second
    #define sz(x) ((int)(x).size())
    #define rdv(x) long long x; cin>>x;
    #define deb(x) cout<<#x<<"="<<x<<endl;
    #define inf 1e18
    #define endl "\n"

    typedef vector<long long> vll;
    typedef long long ll;
    typedef pair<long long,long long> pii;
    typedef long double ld;
    mt19937 mrand(random_device{}());
    const ll mod=1000000007;
    int rnd(int x) { return mrand() % x;}
    ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
    bool prime[200001];
    void SieveOfEratosthenes()
    {
        memset(prime, true, sizeof(prime));
        prime[1]=false;
        for (int p=2; p*p<=200000; p++)
        {
            if (prime[p] == true)
            {
                for (int i=p*p; i<=200000; i += p)
                    prime[i] = false;
            }
        }
        return;
    }

    ll ceil(ll x,ll y)
    {
        ll ans=x/y;
        if(x%y)
            ans++;

        return ans;
    }

    void file_i_o(){
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
    }
    // head

    void solve()
    {
        ll n,k;
        cin>>n>>k;

        vll arr(n);
        rep(i,0,n)
        {
            cin>>arr[i];
        }

        map<ll,ll>mp;

        set<ll> s;
        for (int i = 0; i <= n; i++)
        s.insert(i);
 
    
    for (int i = 0; i < k; i++)
        {s.erase(arr[i]);
            mp[arr[i]]++;
         } 
    ll mex = *(s.begin());
    //deb(mex)
    
    // for(auto it:s)
    // {    
    //     deb(it)
    // }
    for (int i = k; i < n; i++) {

        mp[arr[i]]++;
         mp[arr[i-k]]--;



        s.erase(arr[i]);

        if(mp[arr[i-k]]==0)
        {
            s.insert(arr[i - k]);
        }
        

   
        ll firstElem = *(s.begin());
        mex = min(mex, firstElem);
    }
        cout<<mex;
        cout<<"\n";
    }
    int main()
    {
        ios_base::sync_with_stdio(false); 			//Used to reduce the time
        cin.tie(NULL);
        cout.tie(NULL);

        file_i_o();

        ll T=1;
        //cin>>T;
        while(T--)
        {
            solve();
        }
    }
 
#include <bits/stdc++.h>

using namespace std;
#define FOR(i, begin, end) for(int i=begin;i<end;i++)





void solve() {
    int N, M;

    vector<int> counter(1500001, -1);

    cin >> N >> M;

    int ans = INT_MAX;

    for (int i = 0; i < N; i++) {
        int elt;
        cin >> elt;

        if (i - counter[elt] > M || (counter[elt] == -1 && i >= M))
            ans = min(ans, elt);
        
        counter[elt] = i;
    }

    for (int i = 0; i < M + 1; i++) {
        if (N - counter[i] > M || counter[i] == -1)
            ans = min(ans, i);
    }
    
    cout << ans << "\n";
}

int main() {
    solve();
}