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 ++){
		ulong r = as[i - 1] + as[i] - x;
		ans += r;
		if(r <= as[i]){
			as[i] -= r;
			}
		else{
			as[i] = 0;
			as[i - 1] = x;
			}
		}
	
	debug as.writeln;
	
	ans.writeln;
	}