import qualified Data.ByteString.Char8 as BC
import Data.IORef
import Control.Monad(forM_, when)
import Data.Maybe(fromJust)

main :: IO()
main = BC.getContents >>= solve.map (fst.fromJust.BC.readInt).tail.BC.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