fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val inputs = mutableListOf<Int>()
    var max = 0
    var maxSecond = 0

    for ( i in 0 until n) {
        val a = readLine()!!.toInt()
        inputs.add(a)
    }

    var maxIndex = 0
    for ( i in 0 until n) {
        if(inputs[i] >= max) {
            max = inputs[i]
            maxIndex = i
        }
    }

    var maxIndexSecond = 0
    for ( i in 0 until n) {
        if(inputs[i] >= maxSecond && i != maxIndex) {
            maxSecond = inputs[i]
            maxIndexSecond = i
        }
    }

    for ( i in 0 until n) {
        if(i == maxIndex) {
            println(inputs[maxIndexSecond])
        } else {
            println(inputs[maxIndex])
        }
    }

}