import Data.IORef
import Control.Monad

main :: IO()
main = do
        n <- readLn
        x <- readLn
        y <- readLn
        print =<< solve (y - x) (min x y) [1..n-2]

solve :: Int -> Int -> [Int] -> IO Int
solve a b xs = do
                a' <- newIORef a
                b' <- newIORef b
                forM_ xs $ \_ -> do
                    z <- readLn
                    x <- readIORef a'
                    y <- readIORef b'
                    when ((z - y) > x) $ writeIORef a' (z - y)
                    when (z < y) $ writeIORef b' z
                readIORef a'