import Control.Monad
import Control.Applicative

main :: IO ()
main = do
    n <- read <$> getLine
    rs <- map read <$> replicateM n getLine
    print $ maximum $ solve rs

solve :: [Int] -> [Int]
solve [] = []
solve (x:xs) = (maximum $ ls'):(solve xs)
    where
        ls = map (subtract x) xs
        ls' = if length ls > 0
                then ls
                else [-999999999]