{
result = 0;
k = -1;
cin>>n>>x;
for(int i = 1 ; i <= n ; i++)
cin>>a[i];
for(int i = 1 ; i < n ; i++)
{
num = a[i] + a[i+1];
if( num > x )
{
m = num - x;
result += m;
if( a[i] < a[i+1] )
{
m = a[i] - x;
if( m >= 0 )
{
a[i] -= x;
}
else
{
a[i] = 0;
a[i+1] += m;
}
}
else
{
m = a[i+1] - x;
if( m >= 0 )
{
a[i+1] -= x;
}
else
{
a[i+1] = 0;
a[i] += m;
}
}
}
}
cout<<result;
return 0;
}