#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<set>
using namespace std;

typedef long long ll;

const int NIL = -1;
const int MAX = 2147483647;
const int INF = -10001;
const int N = 1000001;
clock_t START, END;
bool debug = false;

int setv[N];

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in18.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}
	int n, K, i, _size = MAX;
	set<int> S;
	queue<int> Q;
	scanf("%d%d", &n, &K);
	vector<int> V(K + 1);
	for (i = 0; i < n; i++)
		scanf("%d", &setv[i]);
	i = 0;
	V[0] = 1;
	Q.push(setv[0]);
	if (setv[0] >= 1 && setv[0] <= K) {
		V[setv[0]]++;
	}
	while (i < n) {
		if (find(V.begin(), V.end(), 0) == V.end()) {
			_size = min(_size, static_cast<int>(Q.size()));
			if (Q.front() >= 1 && Q.front() <= K) {
				V[Q.front()]--;
			}
			Q.pop();
		}
		else {
			i++;
			Q.push(setv[i]);
			if (setv[i] >= 1 && setv[i] <= K) {
				V[setv[i]]++;
			}
		}
	}
	if (_size == MAX)
		printf("0\n");
	else
		printf("%d\n", _size);
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}
