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!int)().array;
    auto b = zip(a, a[1..$]).map!"a[0]+a[1]".array();
    b[] -= x;
    long ans = b.reduce!"max(0, a) + max(0, b)";
    for (size_t i = 0; i < b.length-1; ++i) {
        const m = min(b[i], b[i+1]);
        if(m > 0) {
            b[i] -= m;
            b[i+1] -= m;
            ans -= m;
        }
    }
    writeln(ans);
}
