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)
    sc.close()

    val filter = A.map(d => A.filter(_ != d))
    filter.distinct.length match {
      case 1 => A.foreach(println)
      case _ => filter.foreach(d => println(d.max))
    }
  }
}