import java.lang.StringBuilder

fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val num = (1..n).map { readLine()!!.toInt() }
    val sorted = num.sortedDescending()
    val ans = StringBuilder()
    num.map { if(it == sorted.first()) sorted[1] else sorted.first() }.forEach { ans.appendln(it) }
    print(ans.toString())

}
