object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val as = List.fill(sc.nextInt())(sc.nextInt())
  val max :: second :: xs = as.sorted.reverse
  as.foreach(a => println(if (a == max) second else max))
}
