#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e9;

int a[110000];
int cnt[110000] = {};

int main(){
	
	long long int n, K;
	cin >> n >> K;
	
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(a[i] > K){
			a[i] = 0;
		}
	}
	a[0] = 0;
	n++;
	
	int ans = INF;
	long long int sum = 0;
	int id = 0;
	
	for(int i = 0; i < n; i++){
		cnt[a[i]]--;
		if(cnt[a[i]] == 0){
			sum -= a[i];
		}
		while(sum != K * (K + 1) / 2){
			if(id >= n){
				break;
			}
			id++;
			cnt[a[id]]++;
			if(cnt[a[id]] == 1){
				sum += a[id];
			}
		}
		//cout << i << " " << id << endl;
		if(sum == K * (K + 1) / 2){
			ans = min(ans, id - i);
		}
	}
	
	if(ans == INF){
		cout << "0" << endl;
	}else{
		cout << ans << endl;
	}
	
	return 0;
}
