import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
static int N = 100010;
static long[] a = new long[N];
static long n,x;
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
n = sc.nextLong();
x = sc.nextLong();
long ans = 0;
a[0] = sc.nextLong();
for(int i = 1;i < n;i ++) {
a[i] = sc.nextLong();
if(a[i] + a[i - 1] > x) {
ans += a[i] + a[i - 1] - x;
a[i] = a[i] - (a[i] + a[i - 1] - x);
}
}
System.out.println(ans);
}
}