fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = List(N) {readLine()!!.toInt()}
    val (max0,max1) = A.sortedDescending().take(2)
    val list = mutableListOf<Int>()
    for (a in A)
        list.add(if(max0 != a) max0 else max1)
    println(list.joinToString("\n"))
}