#include <stdio.h>
#include <stdlib.h>

int main()
{
  int *a, *c;
  int i, n, k, tail, minlen, nzero;
  scanf("%d %d", &n, &k);
  a = (int*)malloc(sizeof(int)*n);
  c = (int*)malloc(sizeof(int)*(k+1));
  nzero = k;
  for (i=0; i<n; i++)  scanf("%u", &a[i]);
  tail = -1;
  minlen = n+1;
  for (i=0; i<n; i++) {
    if (a[i]>k) continue;
    if (tail<0) tail = i;
    if (c[a[i]]++==0) nzero--;
    while (nzero==0) {
      if (i-tail+1<minlen) minlen = i-tail+1;
      if (c[a[tail++]]--==1) nzero++;
    }
  }
  printf("%d\n", minlen>n?0:minlen);
  return 0;
}

