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];
    int[] a = readln.chomp.split.map!(x => x.to!int).array;

    int count = 0;

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