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 [_,x] = pm (0,0)
  where
  pm (s,p) []   = s
  pm (s,p) (a:as)
    | p+a <= x  = pm (s,a) as
    | p <= x    = pm (s+p+a-x,x-p) as
    | otherwise = pm (s+p+a-x,0) as