import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val arr = mutableListOf<Int>()
  for (i in 0 until  n)
    arr.add(readLine()!!.toInt())
  var max1 = -1
  var max1Idx = -1
  for (i in 0 until n) {
    val v = arr[i]
    if (max1 < v) {
      max1 = v
      max1Idx = i
    }
  }
  var max2 = -1
  for (i in 0 until n) {
    if (i == max1Idx)
      continue
    val v = arr[i]
    if (max2 < v) {
      max2 = v
    }
  }
  val pw = PrintWriter(System.out)
  for (i in 0 until n) {
    if (i == max1Idx)
      pw.println(max2)
    else
      pw.println(max1)
  }
  pw.flush()
}

fun debug(vararg objs: Any) {
  System.err.println(Arrays.deepToString((objs)))
}