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 => max(0, a[0]+a[1]-x)).array();
    long ans;
    foreach(i; 0..a.length-1) {
        immutable m = min(a[i], a[i+1]);
        a[i] -= m;
        a[i+1] -= m;
        ans += m;
    }
    ans += a.reduce!"a+b";
    writeln(ans);
}
