object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val A = List.fill(N)(sc.nextInt).toVector
    sc.close()

    val sorted = A.sorted
    A.foreach(d => {
      if (d == sorted.last) {
        println(sorted(sorted.length - 2))
      } else {
        println(sorted.last)
      }
    })
  }
}