main = do
  _ <- getLine
  content <- getContents
  let inputs = map (read :: String -> Int) $ lines content
  print $ findMaxProfit 0 0 inputs

findMaxProfit :: Int -> Int -> [Int] -> Int
findMaxProfit m n [] = n - m
findMaxProfit 0 0 (x:xs) = findMaxProfit x 0 xs
findMaxProfit m 0 (x:xs) = findMaxProfit m x xs
findMaxProfit m n (x:xs)
  = maximum [(findMaxProfit m n xs)
           , (findMaxProfit x 0 xs)
           , (findMaxProfit m x xs)]