fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var a = mutableListOf<Int>()
    var t = 0
    var max = -1
    var max2 = -1
    var dmax = false
    for (i in 0 until n){
        t = readLine()!!.toInt()
        a.add(t)
        if (t > max){
            max = t
        }else if (t > max2){
            max2 = t
        }
    }
    for (i in 0 until n){
        if (a[i] == max) println(max2)
        else println(max)
    }
}