import Control.Applicative
import Data.List (sort)

solve [] = 0
solve [x] = x
solve xs =
  let ys = zipWith3 (\x y z->head.tail $ sort [x,y,z] ) xs (tail xs) ((tail.tail) xs)
  in solve ys

main = do
  _ <- getLine 
  ns <- map read.words <$> getLine :: IO [Int]
  print $ solve ns
