import java.util.*
import java.io.PrintWriter
 
fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val aList = (1..n).map { sc.nextInt() }

    (1..n).forEach { i ->
        val ai = aList[i - 1]
        val max = sortedAList[sortedAList.size - 1]
        if (max == ai) {
            println(sortedAList[sortedAList.size - 2])
        } else {
            println(max)
        }
    }
    out.flush()
}