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