#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 

#define int         long long
#define ull         unsigned long long
#define ll          long long
#define M           998244353
#define pb          push_back
#define p_q         priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp          make_pair
#define lb          lower_bound
#define ub          upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for (int i=begin;i<end;i++)
#define repd(i, begin, end) for (int i=end-1;i>=begin;i--)
#define ini(a,n,b)  for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)     __builtin_popcountll(a)
#define hell        1000000007
#define re          resize
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update >
const int INF=1e18;
const int N=3e5+5;

int powm(int a,int b,int mod)
{
  int res=1;
  while(b)
  {
    if(b&1) 
    res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
  }
 
  return res;
}

int pow(int a,int b)
{
  int res=1;
  while(b)
  {
    if(b&1) 
    res=(res*a);
      a=(a*a);
      b>>=1;
  }
 
  return res;
}


signed main(void)
{ios
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
    #endif

    
    int tests=1;
    // cin>>tests;
    while(tests--)
    {
      
      int n,m;
      cin>>n>>m;
      int ans=m;
      multiset<int> s;
      vi a(n);
      rep(i,0,n) cin>>a[i];
      rep(i,0,m) s.insert(i);
      map<int,int> vis;
      rep(i,0,n)
      {
        vis[a[i]]++;
        if(s.find(a[i])!=s.end()) s.erase(a[i]);
        if(i>=m-1)
        {
           if(sz(s)!=0) 
           {
             int mn=*s.begin();
             ans=min(ans,mn);
           }

           vis[a[i-(m-1)]]--;
           if(!vis[a[i-(m-1)]]) s.insert(a[i-(m-1)]);
        }
      }
      cout<<ans<<endl;
    }

                      
}





#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> pre(n);
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		pre[num].emplace_back(i);
	}
	for (int i = 0; i < n; i++) {
		int next = -1;
		pre[i].emplace_back(n);
		for (int j = 0; j < pre[i].size();j++) {
			if (pre[i][j] - next - 1 >= m) {
				cout << i;
				return 0;
			}
			next = pre[i][j];
		}
	}
	cout << n;
}