
object Main extends App{
  import scala.io.StdIn._
  val n: Int = readLine.trim.toInt
  val numbers = Array.tabulate(n){ _ ⇒ readLine.trim.toInt}.sorted.take(4)
  println(numbers.combinations(2).flatMap{_.permutations}.map{_.mkString("").toInt}.toList.sorted.apply(2))
}
