import Data.IORef
import Control.Monad
 
main :: IO()
main = getLine >> getContents >>= (\(x:y:xs) -> solve (y - x) (min x y) xs).map read.lines >>= print
 
solve :: Int -> Int -> [Int] -> IO Int
solve a b xs = do
                a' <- newIORef a
                b' <- newIORef b
                forM_ xs $ \z -> do
                    x <- readIORef a'
                    y <- readIORef b'
                    when (z - y > x) $ writeIORef a' (z - y)
                    when (z < y)     $ writeIORef b' z
                readIORef a'