#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
// #define MOD (998244353)
#define INF (1e9+7)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
using P=pair<ll,ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pl(T x){cout << x << " ";}
template<class T>void pr(T x){cout << x << endl;}
template <class T, class... Ts> inline void pr(T Tar, Ts... ts) { std::cout << Tar << " "; pr(ts...); return; }
template<class T>void prvec(vector<T>& a){rep(i, (int)a.size()-1){pl(a[i]);} pr(a.back());}
template<class T>void prarr(arr<T>& a){rep(i, (int)a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}

int main()
{
    int n,m; cin >> n >> m;
    vint cnt(n+1, 0);
    vint(a, n);

    int ans = INF;
    rep(i, m){
        cnt[a[i]]++;
    }
    rep(i, n+1){
        if(cnt[i]==0) chmin(ans, i);
    }

    FOR(i, 1, n-m+1){
        cnt[a[i-1]]--;
        cnt[a[i+m-1]]++;
        if(cnt[a[i-1]]==0) chmin(ans, a[i-1]);
    }

    pr(ans);
    return 0;}
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(1.5e6 + 10);
std::set<int> s;
int n, m, a[N], b[N], ans = 1e9;

void Ins(int x) { if (!b[x]++) s.erase(x); }
void Ers(int x) { if (!--b[x]) s.insert(x); }

int main()
{
#ifndef ONLINE_JUDGE
	file(cpp);
#endif
	n = read(), m = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	for (int i = 0; i <= n; i++) s.insert(i);
	for (int i = 1; i <= m; i++) Ins(a[i]);
	ans = std::min(ans, *s.begin());
	for (int i = m + 1; i <= n; i++)
		Ins(a[i]), Ers(a[i - m]), ans = std::min(ans, *s.begin());
	printf("%d\n", ans);
	return 0;
}
