import Control.Monad (replicateM)
main = do
        n <- readLn
        nums <- replicateM n readLn
        print.maxProfit $ nums
maxProfit :: [Int] -> Int
maxProfit = fst.searchMinMax

searchMinMax :: [Int] -> (Int, Int)
searchMinMax (x:y:xs) = foldl func (y-x,min x y) xs

func (dif,l) x
    | l > x     = (max (x-l) dif,x)
    | otherwise = (max (x - l) dif,l)