import std.stdio;
import std.string;
import std.array;
import std.algorithm;
import std.conv;

void main() {
    auto buf = readln.chomp.split.map!(x => x.to!int);
    int N = buf[0];
    int x = buf[1];
    ulong[] a = readln.chomp.split.map!(x => x.to!ulong).array;

    ulong count = 0;

    foreach(i; 0 .. N) {
        if (i == 0) {
            if (a[i] > x) {
                count += a[i] - x;
                a[i] -= count;
            }
            continue;
        }
        ulong sum = a[i-1] + a[i];
        if (sum > x) {
            count += sum - x;
            a[i] -= sum - x;
        }
    }
    writeln(count);
}
