fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    val xs = (1..n).map { readLine()!!.toInt() }
    val ys = xs.sorted()
    val max = ys.last()
    for(i in 0 until n){
        println(if(xs[i] == max) ys[ys.size -2] else max)
    }
}