import java.io.PrintWriter
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

    fun func() {
        val n = nextInt()
        var index = 0
        var max = 0
        var oldMax = 0
        for(i in 0 until n){
            val a = nextInt()
            if(a>max){
                index = i
                oldMax = max
                max = a
            }else{
              if(a==max&&index!=i){oldMax = max}
            }
        }
        for(i in 0 until n){
            if(i==index){println(oldMax)}
          	else println(max)
        }
    }

// 入力取得
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

fun println(value : Any) {
    pw.println(value)
}
