import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	int n, x;
	{
		int[] tmp = readln.chomp.split.map!(to!int).array;
		n = tmp[0], x = tmp[1];
		}
	
	ulong[] as = readln.chomp.split.map!(to!ulong).array;
	
	ulong ans = 0;
	
	for(int i = 1; i < as.length; i ++){
		if(as[i - 1] + as[i] < x) continue;
		ulong r = as[i - 1] + as[i] - x;
		if(r <= as[i]){
			ans += r, as[i] -= r;
			}
		else{
			ans += as[i], as[i] = 0;
			ans += as[i - 1] - x, as[i - 1] = x;
			}
		}
	
	debug as.writeln;
	
	ans.writeln;
	}