import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt()
  val array = (for (i <- 0 until N) yield sc.nextInt()).toArray
  val flags = Array.fill[Int](K+1)(0)

  def solver(l:Int, r:Int, len:Int):Int = {
    def isFilled:Boolean = flags(0) == K
    def inRange(x:Int):Boolean = 1 <= x && x <= K

    if (r >= N && !isFilled) if (len < N+1) len else 0
    else if (isFilled) {
      val i = array(l)
      if (inRange(i)) {
        flags(i) -= 1
        if (flags(i) == 0) flags(0) -= 1 
        solver(l+1, r, len min (r -l))
      }
      else solver(l+1, r, len)
    }
    else {
      val i = array(r)
      if (inRange(i)) {
        if (flags(i) == 0) flags(0) += 1 
        flags(i) += 1
      }
      solver(l, r+1, len)
    }
  }

  println(solver(0, 0, N+1))

}
