module Main where
--import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: Int -> [Int] -> Int
solve n l = iter (-10^9) (-10^9, 10^9) (n-1) (reverse l) where
    iter _ (ms, mb) _ [] = ms - mb
    iter mr (ms, mb) i (x:xs) = iter (max mr x) next (i-1) xs where
        next | mr - x > ms - mb = (mr, x)
             | otherwise = (ms, mb)

main :: IO() 
main = do
    n <- readLn
    l <- replicateM n readLn :: IO [Int]
    print (solve n l)

