n, k = gets.split.map(&:to_i)
arr = Array.new(n){0}
a = gets.split.map(&:to_i).map{|i| i-1}
if n < k then
  puts 0
  exit
end

# initial condition
k.times{|i|
  arr[a[i]] += 1
}
min = n+1

r = k
l = 0
loop do
  break if l > n - k

  # extract unused number
  rest = {}
  k.times{|i|
    rest[i] = 1 if arr[i] == 0
  }

  # expand window size to include all numbers in the window
  while rest.size > 0 && r+l < n
    arr[a[r+l]] += 1
    rest.delete(a[r+l])
    r += 1
  end

  # shrink the window size while all numbers exist in the window
  while a[l] >= k || arr[a[l]] > 1
    arr[a[l]] -= 1
    l += 1
    break if l > n
  end

  # update the minimum window size
  min = r - l if min > r - l

  # is minimum condition?
  break if min == k

  # slide window to left
  arr[a[l]] -= 1
  l += 1
  #  p arr
end

if min > n
  puts 0
else
  puts min
end