import Control.Applicative

solve :: Integer -> [Integer] -> Integer
solve n [x]       = n
solve n (x:x':xs) = (min n $ x'-x) + solve n (x':xs) 

main = do
    [_,n] <- map read . words <$> getLine
    xs    <- map read . words <$> getLine
    putStrLn $ show $ solve n xs
