import scala.io.StdIn

object Main extends App {

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


  val ans = {
    seq.foldLeft(0,0,0)((acc,e) => {
      // println(acc._1 + " " + acc._2 + " " + acc._3)
      if(acc._1 != e) {
       if(acc._1 != acc._2) {
         if(acc._2 < acc._1) (e, 1, acc._3 + acc._2)
         else (e, 1, acc._3 + acc._2 - acc._1)
       }
       else (e, 1, acc._3)
      } else {
        (e, acc._2+1, acc._3)
      }
    })._3
  }

  println(ans)
}