let N = stdin.ReadLine() |> int

let A =
    [| for _ in [ 1..N ] do
        yield stdin.ReadLine() |> int |]

let max1 = A |> Array.max

let max2 =
    A
    |> Array.filter ((<>) max1)
    |> Array.append [| 0 |]
    |> Array.max

A
|> Array.map (fun x ->
    if x <> max1 || max2 = 0 then max1
    else max2)
|> Array.iter stdout.WriteLine