import java.util.*
 
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val t = mutableListOf<Int>()
    val sorted = mutableListOf<Int>()
    repeat(n) {
        val x = sc.nextInt()
        t.add(x)
        sorted.add(x)
    }
 
    sorted.sortDescending()
 
    for (x in t) {
        if (x == sorted[0]) {
            println(sorted[1])
        } else {
            println(sorted[0])
        }
    }
}