{-# OPTIONS_GHC -Wall #-}

readInt :: String -> Int
readInt = read

solve :: [Int] -> Int
solve a = maximum b
    where
        b    = zipWith (-) (tail a) mins
        mins = scanl1 min a

main :: IO ()
main = do
    _ <- fmap readInt getLine
    a <- fmap (map readInt . words) getContents
    let ans = solve a
    print ans

