fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val aList = (1..n).map { readLine()!!.toInt() }
  val sortedAList = aList.sortedDescending()

  for (i in 0 until n) {
    val a = aList[i]
    println(if (a == sortedAList[0]) sortedAList[1] else sortedAList[0])
  }
}

