import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    n <- getInt
    as <- replicateM n getInt
    let (m1 : m2 : _) = reverse $ sort as
    let ans = map (solve m1 m2) as
    mapM_ print ans

solve m1 m2 a | a == m1 = m2
              | otherwise = m1