import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)


    val n = argList.nextLine().toInt()
    val a = mutableListOf<Int>()

    while (argList.hasNext()) {
        a.add(argList.nextLine().toInt())
    }

    val e = ExceptionHandling()
    e.execute(n, a)

}

class ExceptionHandling {
    fun execute(n: Int, a: List<Int>) {
        val firstMaxAmout = a.max()
        val secondMaxAmout = when(a.filter { it == firstMaxAmout }.size) {
            1 -> a.filter { it != firstMaxAmout }.max()
            else -> firstMaxAmout
        }

        a.forEach {
            if (it == firstMaxAmout) {
                println(secondMaxAmout)
            } else {
                println(firstMaxAmout)
            }
        }
    }
}