object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt
  val numbers = Array.tabulate(N)(_ => sc.nextInt)
  val numbersSorted = numbers.sorted.reverse
  val highest = numbersSorted(0)
  val secondHighest = numbersSorted(1)

  for(i <- 0 until N) {
    if (numbers(i) == highest) println(secondHighest)
    else println(highest)
  }
}