#include <iostream>
using namespace std;
long long n, x, temp, key = 0;
long long a[1000005] = {0};
int main(int argc, char const *argv[])
{
cin >> n >> x;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 0; i < n - 1; i++)
{
if (a[i] + a[i + 1] - x <= 0)
{
continue;
}
if (a[i] > a[i + 1])
{
temp = a[i] - x;
a[i] = x;
key += temp;
temp = a[i] + a[i + 1] - x;
a[i + 1] -= temp;
key += temp;
}
else if (a[i] < a[i + 1])
{
temp = a[i] + a[i + 1] - x;
a[i + 1] -= temp;
key += temp;
}
else if (a[i] = a[i + 1])
{
temp = a[i] - x;
a[i] = x;
key += temp;
temp = a[i] + a[i + 1] - x;
a[i + 1] -= temp;
key += temp;;
}
}
cout << key;
system("pause");
return 0;
}