import Data.List
import qualified Data.ByteString.Char8 as B
main = breadIs >>= main' . last
    where
        main' t = breadIs >>= print . solve t 0

solve :: Int -> Int -> [Int] -> Int
solve t acc (x : y : zs)
    | y - x < t = solve t (acc + y - x) (y : zs)
    | otherwise = solve t (acc + t) (y : zs)
solve t acc (_ : _) = acc + t
solve _ acc _ = acc

breadIs :: IO [Int]
breadIs = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)
