import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt()
    val as = (1 to n).map(_ => StdIn.readInt()).toVector
    val maxis = (0 until n).foldLeft((0, 0)){(acc, i) =>
      if (as(i) > as(acc._1)) (i, acc._1)
      else if (as(i) > as(acc._2) || acc._1 == acc._2) (acc._1, i)
      else acc
    }
    (0 until n).foreach{ i =>
       val ans = if (i == maxis._1) as(maxis._2) else as(maxis._1)
       println(ans)       
    }
  }

}