object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, x = sc.nextInt()
  val a = Array.fill(n)(sc.nextInt())
  var ans = 0L
  for (i <- 1 until n) {
    if (a(i-1) + a(i) > x) {
      if (x >= a(i-1)) {
        ans += a(i-1) + a(i) - x
        a(i) -= a(i-1) + a(i) - x
      } else {
        ans += a(i)
        a(i) = 0
        ans += a(i-1) + a(i) - x
        a(i-1) -= a(i-1) + a(i) - x
      }
    }
  }
  println(ans)
}