#include <iostream>
#include <vector>

int main() {
  uint32_t N = 0, K = 0;
  std::cin >> N >> K;
  std::vector<uint32_t> A(N);
  for (auto &&a : A) std::cin >> a;

  size_t min_len = -1, K_count = 0;
  std::vector<uint32_t> count(K + 1, 0);
  for (size_t start = 0, end = 0; start < N; start++) {
    while (end < N && K_count < K) {
      if (A[end] <= K && count[A[end]]++ == 0) K_count++;
      end++;
    }
    if (K_count < K) break;
    min_len = std::min(min_len, end - start);
    if (A[start] <= K && --count[A[start]] == 0) K_count--;
  }

  std::cout << (min_len > N ? 0 : min_len) << std::endl;

  return 0;
}
