void main()
{
    long[] tmp = readln.split.to!(long[]);
    long n = tmp[0], x = tmp[1];
    long[] a = readln.split.to!(long[]);

    long cnt;
    foreach (i; 1 .. n)
    {
        long diff = a[i] + a[i-1] - x;
        if (diff > 0)
        {
            a[i] = max(0, a[i]-diff);
            cnt += diff;
        }
    }

    cnt.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;