import Data.List

main=do
    line<-getLine
    ctx<-getContents
    let p =[read x::Int | x<-lines ctx]
    let m=maxL p
    let r= length [1 | x<-p,(maxL p)==x]
    let s= if r==1 then maxL [x |x<-p ,x /= m] else m

    output p m s
    
maxL :: [Int]->Int
maxL [x] =x
maxL (x:xs) = max x (maxL xs)

output :: [Int]->Int->Int->IO()
output [] _ _ = return()
output (x:xs) m s
    | m/=s =do
         if x==m then putStrLn (show s) else putStrLn (show m )
         output xs m s
    | otherwise =do
         putStrLn (show m)
         output xs m s