import Control.Monad
import Data.List

main = do
    n <- readLn
    a <- replicateM n (readLn :: IO Int)
    let b = sort a
    mapM_ print $ map (\x -> if x == last b then last (init b) else last b) a
