#import <stdio.h>
typedef long long INT;

int main() {
    INT N,x;
    scanf("%lld %lld", &N,&x);
    INT cost = 0;
    INT last;
    for (INT i=0; i<N; i++){
        INT a;
        scanf("%lld",&a);
        if (i==0) {
            last = a;
            continue;
        }
        if (last + a <= x) {
            last = a;
            continue;
        }
        last = x - last;
        cost += a - last;
    }
    
    printf("%lld", cost);
}
