import Control.Arrow
import Control.Monad.State.Strict
 
main :: IO()
main = getLine >> getContents >>= print.fst.(\(x:y:ys) -> solve ys (y- x, min x y)).map read.lines
 
solve :: [Int] -> (Int, Int) -> (Int, Int)
solve ys = execState $ do
            forM_ ys $ \y -> do
              (a, b) <- get
              modify $ (max (y - b)) *** (min y)
            return ()