import Control.Monad
import Data.List

main = do
  li <- getLine
  let n = read li :: Int
  as <- forM [1..n] (\_ -> do
    li <- getLine
    return $ read li
  )
  let ans = compute as
  sequence_ $ map print ans

compute :: [Int] -> [Int]
compute as = [ if a == m1 then m2 else m1 | a <- as ]
  where (m1:m2:_) = reverse $ sort as
