import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

-- [5, 3, 1, 3, 4, 3]
-- [(5,-inf), (min(5,3), max(5-3,-inf)=(3,-2), (min(3,1), max(1-3,-2))=(1,-2),...]

main = do
    n<- getLine
    a<- map (read::String->Int) <$> replicateM (read n) getLine
    print $ snd $ foldl work (inf, -inf) a
      where
        inf = 10^9
        work (cur_min, ans) x = (min cur_min x, max (x-cur_min) ans)
