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

    val max2 = A.sorted.takeRight(2)
    A.foreach(d => {
      if (d != max2.last) {
        println(max2.last)
      } else {
        println(max2.head)
      }
    })
  }
}