import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    int N, X; readf("%d %d\n", &N, &X);
    auto A = readln.chomp.split(" ").map!(to!int).array;
    long ans = 0;
    if (A[0] > X) {
        ans += A[0] - X;
        A[0] = X;
    }
    for (int i = 1; i < N; i++) {
        ans += max(0, A[i] + A[i - 1] - X);
        A[i] = min(A[i], X - A[i - 1]);
    }
    //log(A);
    writeln(ans);
}
