#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define INF 999999999

using namespace std;

int n, s, k, ans;
int a[105000];



void solve()
{

	int ret = n + 1;

	int l = 0, r = 0;
	map<int,int> m;
	while (1) {

		while (r < n && (int)m.size()<k) {
			if (a[r] <= k) {
				m[a[r]]++;
			}
			r++;
		}
		if ((int)m.size() < k)break;
		ret = min(ret, r-l);
		if (a[l] <= k) {
			if (m[a[l]] == 1)m.erase(a[l]);
			else m[a[l]]--;
		}
		l++;
	}

	if (ret > n)ret = 0;
	printf("%d\n", ret);

}


int main()
{
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		
	}
	solve();

	return 0;
}