
object Main{
	def main(args:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n=s.nextInt
		val a=Array.tabulate(n)(i=>(s.nextInt,i)).sorted

		for(i<-0 to n-1)
			println(if(a(n-1)._2==i)a(n-2)._1 else a(n-1)._1)
	}
}
