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 aWithIndex = a.mapIndexed { index, i -> index to i }

        val sorted = aWithIndex.toList().sortedBy { it.second * -1 }

        a.forEachIndexed { index, i ->
            if (index == sorted[0].first) {
                println(sorted[1].second)
            } else {
                println(sorted[0].second)
            }
        }
    }
}