import           Control.Applicative
import           Control.Monad

profit :: [Int] -> Int
profit (a:b:cs) = f a (b - a) (b:cs)
  where
    f minv maxv []     = maxv
    f minv maxv (x:xs) = f (min minv x) (max maxv (x - minv)) xs

main :: IO ()
main = do
    getLine
    xs <- fmap read . lines <$> getContents :: IO [Int]
    print $ profit xs

