let () =
    let main () =
        let n = Scanf.sscanf (read_line ()) "%d" (fun a -> a) in
        let arr = Array.init n (fun _ -> int_of_string (read_line ())) in
        let arr2 = Array.copy arr in
        Array.sort (fun a b -> compare b a) arr2;
        for i = 0 to n - 1 do
            Printf.printf "%d\n" (if arr.(i) = arr2.(0) then arr2.(1) else arr2.(0))
        done
    in
    main ()