import           System.IO
import           Control.Monad
import           Control.Applicative


data Res = Res {
  oldmax :: Int,
  oldmin :: Int
} deriving Show

f :: Res -> Int -> Res
f acc a = Res (max (oldmax acc) (a - oldmin acc)) (min (oldmin acc) a)

main = do
  n    <- readLn :: IO Int
  list <- replicateM n (readLn :: IO Int)
  putStrLn $ show $ oldmax $ foldl f
                                   Res {oldmax = minBound, oldmin = maxBound}
                                   list

