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

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

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

  # elongate window 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

  # no possibility to find minimum
  break if rest.size > 0

  # shrink the window while all numbers are included in the window
  while a[l] >= k || arr[a[l]] > 1
    arr[a[l]] -= 1
    l += 1
    break if l > n - k
  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
  rest[a[l]] = 1 # drop out from the window
  l += 1

  #  p arr
end

if min > n
  puts 0
else
  puts min
end