import Control.Monad (replicateM)

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

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