import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val as = List.fill(n)(sc.nextInt())

    val ass = as.sorted.reverse
    val (m, mm) = (ass.head, ass.tail.head)

    as.foreach {
      case i @ `m` => println(mm)
      case i       => println(m)
    }
  }
}
