import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val list = mutableListOf<Int>()
    for(i in 0..n-1){
        list.add(scanner.nextInt())
    }
    val list2 = mutableListOf<Int>()
    list2.addAll(list)
    list2.sortDescending()
    val max = list2.get(0)
    val max2 = list2.get(1)
    for(i in 0..n-1) {
        if(list.get(i) === max){
            println(max2)
        }
        else println(max)
    }
}