object Solution { def main(args: Array[String]) { val sc = new java.util.Scanner (System.in); var n = sc.nextInt(); var types = new Array[Int](n); for(types_i <- 0 to n-1) { types(types_i) = sc.nextInt(); } var birdCounts = scala.collection.mutable.Map[Int, Int]() for(t <- types) { if(birdCounts.contains(t)) { birdCounts(t) = birdCounts(t) + 1 } else { birdCounts(t) = 1 } } import scala.collection.immutable.ListMap val (key, value) = ListMap(birdCounts.toSeq.sortWith(_._1 < _._1).sortWith(_._2 > _._2):_*).head println(key) } }