Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim arrayA(0 To n - 1) As Integer
    Dim max As Integer = 1
    Dim secondMax AS Integer = 1
    For i As Integer = 0 To n - 1
      arrayA(i) = Integer.Parse(Console.ReadLine())
      If arrayA(i) > max Then
        secondMax = max
        max = arrayA(i)
      ElseIf arrayA(i) > secondMax Then
        secondMax = arrayA(i)
      End If
    Next
    For i As Integer = 0 To n - 1
      Dim output As Integer = max
      If arrayA(i) = output Then output = secondMax
      Console.WriteLine(output.ToString())
    Next
  End Sub
End Class