// -*- coding:utf-8-unix -*-
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::LinkedList;
use std::collections::VecDeque;
use std::fs::File;
use std::io;
use std::io::prelude::*;
 


const INF: i64 = 1223372036854775807;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
type vi = Vec<i64>;
type vf = Vec<f64>;
type vu = Vec<usize>;
type vvi = Vec<Vec<i64>>;
type vvf = Vec<Vec<f64>>;
type vvu = Vec<Vec<usize>>;

fn readi() -> i64 {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    str.trim().parse::<i64>().unwrap()
}

fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
fn readiii() -> (i64, i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
fn readvi() -> vi {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let iter = str.split_whitespace();
    iter.fold(Vec::new(), |mut acc, x| {
        acc.push(x.parse::<i64>().unwrap());
        acc
    })
}

fn readvvi(n: usize) -> vvi {
    let mut res: vvi = Vec::new();
    for _ in 0..n {
        let mut str = String::new();
        let _ = stdin().read_line(&mut str).unwrap();
        let iter = str.split_whitespace();
        res.push(iter.fold(Vec::new(), |mut acc, x| {
            acc.push(x.parse::<i64>().unwrap());
            acc
        }));
    }
    res
}

fn prtni(n: i64) {
    println!("{}", n);
}
fn prti(n: i64) {
    print!("{} ", n);
}

fn readu() -> usize {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    str.trim().parse::<usize>().unwrap()
}

fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}
fn readuuu() -> (usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}
fn readvu() -> vu {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let iter = str.split_whitespace();
    iter.fold(Vec::new(), |mut acc, x| {
        acc.push(x.parse::<usize>().unwrap());
        acc
    })
}

fn readvvu(n: usize) -> vvu {
    let mut res: vvu = Vec::new();
    for _ in 0..n {
        let mut str = String::new();
        let _ = stdin().read_line(&mut str).unwrap();
        let iter = str.split_whitespace();
        res.push(iter.fold(Vec::new(), |mut acc, x| {
            acc.push(x.parse::<usize>().unwrap());
            acc
        }));
    }
    res
}

fn prtnu(n: usize) {
    println!("{}", n);
}
fn prtu(n: usize) {
    print!("{} ", n);
}

fn readf() -> f64 {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    str.trim().parse::<f64>().unwrap()
}

fn readff() -> (f64, f64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<f64>().unwrap(),
        iter.next().unwrap().parse::<f64>().unwrap(),
    )
}
fn readfff() -> (f64, f64, f64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<f64>().unwrap(),
        iter.next().unwrap().parse::<f64>().unwrap(),
        iter.next().unwrap().parse::<f64>().unwrap(),
    )
}
fn readvf() -> vf {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let iter = str.split_whitespace();
    iter.fold(Vec::new(), |mut acc, x| {
        acc.push(x.parse::<f64>().unwrap());
        acc
    })
}

fn readvvf(n: usize) -> vvf {
    let mut res: vvf = Vec::new();
    for _ in 0..n {
        let mut str = String::new();
        let _ = stdin().read_line(&mut str).unwrap();
        let iter = str.split_whitespace();
        res.push(iter.fold(Vec::new(), |mut acc, x| {
            acc.push(x.parse::<f64>().unwrap());
            acc
        }));
    }
    res
}

fn prtnf(n: f64) {
    println!("{}", n);
}
fn prtf(n: f64) {
    print!("{} ", n);
}



fn solve(){
    let(n,x) = readii();
    let mut vec =readvi();
    let mut res:i64 = 0;
    for i in 0..(n-1) {
        let index:usize = i as usize;

        if vec[index] + vec[index+1] > x {
            let diff = vec[index] + vec[index+1] - x;
            res += diff;
            vec[index+1] -= diff;
            if vec[index+1] < 0 {
                vec[index+1] = 0;
                
            }
        }
    }
    println!("{:?}", res);



}
fn main() {
    solve()
    
}


Measured memory_bytes: 3976