//#include "pch.h"
#include <iostream>

using namespace std;

long long a[100000];

int main() {

	long long n, x;

	cin >> n >> x;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	long long ans = 0;

	if (a[0] > x) {
		ans += a[0] - x;
		a[0] = x;
	}


	for (int i = 0; i < n - 1; i++) {
		if (a[i] + a[i + 1] > x) {
			long long buf = a[i] + a[i + 1] - x;
			ans += buf;
			a[i + 1] -= buf;
		}
	}

	cout << ans << endl;


//	system("pause");
	return 0;
}