import qualified Data.List as L

main :: IO ()
main = do
    n  <- words <$> getLine
    xs <- fmap read . words <$> getLine
    answer $ solve xs

type Answer = Int
answer :: Answer -> IO ()
answer = print

solve :: [Int] -> Int
solve = go
  where
    median (x, y, z)
      | max x (min y z) == x && min x (max y z) == x = x
      | max y (min z x) == y && min y (max z x) == y = y
      | max z (min x y) == z && min z (max x y) == z = z
    inner (x : y : z : xs) = median (x, y, z) : inner (y : z : xs)
    inner               _  = []
    go [x] = x
    go  xs = go $ inner xs
