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

k.times{|i|
  arr[a[i]] += 1
}
#p arr

min = n+1

r = k
n.times{|l|
  rest = {}
  k.times{|i|
    rest[i] = 1 if arr[i] == 0
  }
  while rest.size > 0 && r+l < n
    arr[a[r+l]] += 1
    rest.delete(a[r+l])
    r += 1
  end
#  p "#{r} #{l} #{arr}"
  min = r - l if min > r - l
  if min == k
    puts min
    exit
  end
  break if r+l > n
  arr[a[l]] -= 1
#  p arr
}

if min > n
  puts 0
else
  puts min
end