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;

    long count = 0;
    foreach(i; 0 .. N) {
        if (a[i] > x) {
            count += a[i] - x;
            a[i] = x;
        }
    }

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

    writeln(count);
}
