import java.util.Scanner

fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	val n = scanner.nextInt()
	val x = scanner.nextLong()
	var ans = 0L

	var bef = scanner.nextLong()	//a1
	repeat(n-1){
		var a = scanner.nextLong()
		if (bef+a>x){
			ans+=bef+a-x
			a =  if (bef-x>0) 0 else x-bef
		}
		bef = a
	}
	println(ans)
}