import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine.toInt
  val seq = StdIn.readLine.split(" ").map(_.toInt).sorted.toBuffer += 0

  val ans = {
    seq.foldLeft(0,0,0)((acc,e) => {
      val c = if(acc._1 != e) 1 else acc._2+1
      val t = if(c == 1 && acc._1 != acc._2) {
        if(acc._1 > acc._2) acc._2 + acc._3
        else acc._2 + acc._3 - acc._1
      } else { acc._3 }

      (e, c, t)
    })._3
  }

  println(ans)
}
