object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val a = Seq.fill(n)(sc.nextInt)

  val max = a.max
  val count = a.count(_ == max)
  for (i <- (0 to n - 1)) {
    if (count == 1 && a(i) == max) {
      val tmp = a.splitAt(i)
      println((tmp._1 ++ tmp._2.tail).max)
    } else {
      print(max)
    }
  }
}