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

main = sol <$> get <*> get >>= print

get = fmap fst . mapMaybe C.readInt . C.words <$> C.getLine

sol [n,x] as = min ev od
  where
  bs = zipWith (((max 0 . subtract x) .) . (+)) as (tail as)
  ev = sum $ pm [] bs
  od = sum$ pm [] (0:bs)

pm s [] = s
pm s [a] = a:s
pm s (a:b:as) = pm (max a b:s) as