import qualified Data.ByteString.Char8 as C
import Data.List

main = C.interact $ put . sol . get

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines

put = C.pack . show

sol [[_,t],ts] = (t+) . sum $ zipWith ((min t .) . (-)) (tail ts) ts
