import java.util.Scanner

object Main extends App {

  val sc: Scanner = new Scanner(System.in)

  val l = Vector.fill(sc.nextInt())(sc.nextInt())
  val fst #:: snd #:: _ = l.toStream.sorted(Ordering[Int].reverse)
  l.foreach(n => println(if (n == fst) snd else fst))

}