#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 15e5 + 5;
map<int,int> mp;
int a[N];

int main()
{
	int n,m;
	cin >> n >> m;
	int minn = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(i <= m){
			mp[a[i]]++;
		}
	}
	for(int i = 0; i <= m+1; i++){
		if(!mp[i]){
			minn = i;
			break;
		}
	}
	for(int i = m+1; i <= n; i++){
		mp[a[i]]++;
		mp[a[i-m]]--;
		if(!mp[a[i-m]]){
			minn = min(a[i-m],minn);
		}
	}
	cout << minn << endl;
    return 0;
}
#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ROUNDUP(a,b) ((a+b-1)/b)
#define YESNO(T) cout<<(T?"YES":"NO")<<endl
#define yesno(T) cout<<(T?"yes":"no")<<endl
#define YesNo(T) cout<<(T?"Yes":"No")<<endl

const int INFint = 1 << 30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007LL;
const double pi = 3.14159265358979;

int si,sj;
vector<vector<int>> tile(50, vector<int>(50));
vector<vector<int>> profit(50, vector<int>(50));
vector<bool> seen(2500,false);
string ans;

void all_resize(){
    return;
}

void all_input(){
    cin >> si >> sj;

    all_resize();

    for (int i = 0; i < 50; i++){
        for (int j = 0; j < 50; j++){
            cin >> tile[i][j];
        }
    }

    for (int i = 0; i < 50; i++){
        for (int j = 0; j < 50; j++){
            cin >> profit[i][j];
        }
    }

    return;
}

void all_output(){

    cout << ans << endl;

    return;
}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    all_input();

    all_output();
}

// 