import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Clue = Tuple!(long, "x", long, "y", long, "h");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

long cnt;

void main()
{
    long n, x;
    scan(n, x);
    auto a = aryread();
    long cnt;
    if (a[0] > x)
    {
        cnt += a[0] - x;
        a[0] = x;
    }
    foreach(i; iota(n - 1))
    {
        auto dif = a[i] + a[i + 1] - x;
        if(dif > 0)
        {
            cnt += dif;
            a[i + 1] -= dif;
        }
    }
    cnt.writeln();
}

void dfs(T)(T g, long current, bool[] visit)
{
    // current.writeln();
    foreach (e; g[current])
    {
        if (!visit[e])
        {
            visit[e] = true;
            dfs(g, e, visit);
            visit[e] = false;
        }
    }
    if (visit.all_true())
        cnt++;
}

bool all_true(bool[] a)
{
    bool ret = true;
    foreach (e; a)
        ret &= e;
    return ret;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
