import           Control.Monad

main :: IO ()
main = do
  [n, x] <- map read . words <$> getLine
  as <- map read . words <$> getLine

  let cost = solve x (mins x as) 0

  print $ sum as - sum (mins x as) + cost
  where
    mins x as = [min x a | a <- as]

solve :: Int -> [Int] -> Int -> Int 
solve _ [_] c = c
solve x (a1: a2: as) c
  | a1 + a2 > x = solve x (x - a1:as) (c + a1 + a2 - x)
  | otherwise = solve x (a2:as) c