#include <iostream>

using namespace std;
const int maxn = 1e5 + 50;
int box[maxn];
int n, x;

int main() {
    while (cin >> n >> x) {
        for (int i = 0; i < n; ++i) {
            cin >> box[i];
        }
        long long sum;
        long long ans=0;
        for (int j = 0; j < n - 1; ++j) {
            sum = box[j] + box[j + 1] - x;
            if(sum<=0)
                continue;
            else if (sum > 0 && box[j+1]-sum>=0) {
                box[j+1]-=sum;
                ans+=sum;
            } else if(sum>0){
                box[j+1]=0;
                ans+=sum;
            }
        }
        cout<<ans<<endl;
    }
}