import Control.Monad
import Text.Printf

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO()
main = do
  n <- readLn
  as <- replicateM n $ getInts
  let aas = concat as
  printf "%s" $ slv2 aas [] []

slv2 ::[Int] -> [Int] -> [String] -> String 
slv2 [a] _ _ = show a
slv2 as ls ret = slv tmp [(head as)] [show (maximum tmp)]
  where tmp = tail as


slv :: [Int] -> [Int] -> [String] -> String
slv [] _ ret = unlines $ reverse ret
slv [a] ls ret = unlines $ reverse ((show (maximum ls)):ret)
slv (a:as) ls ret = slv as (a:ls) ((show maxa):ret)
  where maxa = maximum [(maximum as), (maximum ls)]