import Control.Applicative
import Control.Monad
import Data.Functor
import Data.List

f :: (Int, Int) -> Int -> (Int, Int)
f (m, r) x = (min m x, max r (x-m))

main = readLn >>= flip replicateM readLn >>= \(x:xs) -> print $ snd $ foldl f (x, -1000000007) xs
