#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;

int a[100002], b[100002];
int main(){
	int n, k, ans = inf;
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n;i++)scanf("%d", &a[i]);
	
	int l = 0, r = 0, sum = 0;
	while(r <= n){
		if(sum == k)ans = min(ans, r-l);
		if(sum < k){
			if(a[++r] <= k){
				if(b[a[r]]++ == 0)sum++;
			}
		}else{
			if(a[++l] <= k){
				if(--b[a[l]] == 0)sum--;
			}
		}
	}
	
	if(ans == inf)printf("0\n");
	else printf("%d\n", ans);
	return 0;
}
