{-# LANGUAGE BangPatterns #-}
module Main where

import Data.Functor
import Data.Bool

main :: IO ()
main = do
  { [n] <- getInts
  ; print =<< loop (maxBound, minBound) n
  }

loop :: (Int, Int) -> Int -> IO Int
loop (_,maxv) 0 = return maxv
loop (!minv, !maxv) !n = do
  { [r] <- getInts
  ; loop (min minv r, max maxv (r - minv)) (n - 1)
  }
  
getInts :: IO [Int]
getInts = map read . words <$> getLine