import java.util
import java.util.Scanner

object Main {
  def solve(N: Int, K: Int, A: Array[Int]): Int = {
    val counts = Array.ofDim[Int](N + 1)
    util.Arrays.sort(A)

    var i = 0
    while(i < N) {
      val j = i
      while(i < N && A(j) == A(i)) i += 1 // A(j)と同じ値の次までiを進める
      val count = i - j
      counts(count) += 1
    }

    var remain = counts.sum - K
    var res = 0
    for {
      i <- 1 to N
      if remain > 0
    } {
      val used = math.min(remain, counts(i))
      remain -= used
      res += used * i
    }

    res
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val K = sc.nextInt()
    sc.nextLine()
    val A = Array.ofDim[Int](N)
    A.indices foreach (i => A(i) = sc.nextInt())
    System.out.println(solve(N, K, A))
  }
}
