import std.stdio, std.conv, std.math, std.string, std.range, std.array,
       std.algorithm;

void main(){
    auto buf = readln().strip().split().map!(to!int)();
    immutable x = buf[1];
    auto a = readln().strip().split().map!(to!long)().array;
    a = zip(a, a[1..$]).map!"a[0]+a[1]".array();
    a[] -= x;
    a = a.map!"max(0, a)".array;
    long ans = a.reduce!"a+b";
    for (size_t i = 0; i < a.length-1; ++i) {
        const m = min(a[i], a[i+1]);
        a[i] -= m;
        a[i+1] -= m;
        ans -= m;
    }
    writeln(ans);
}
