let readInt _ = stdin.ReadLine() |> int

()
|> readInt
|> fun x -> [ 1 .. x ]
|> List.fold (fun (m1, m2, l: int list) _ ->
    let current = () |> readInt
    let next = [ current ] |> List.append l
    if m1 <= current then (current, m1, next)
    elif m2 <= current then (m1, current, next)
    else (m1, m2, next)) (0, 0, [])
|> fun (m1, m2, l) ->
    for i in l do
        if i = m1 then printfn "%d" m2 else printfn "%d" m1
