#undef LOCAL
//#define LOCAL


#ifndef LOCAL
#define NDEBUG
#endif
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <cerrno>
#include <cfenv>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <sys/time.h>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

#define sz(a)               ((int) (a).size())
#define all(a)              (a).begin(), (a).end()
#define rall(a)             (a).rbegin(), (a).rend()
#define unq(a)              (a).resize(unique(all(a)) - (a).begin())
#define rep(i, b)           for (int (i) = 0; (i) < (b); ++(i))
#define repab(i, a, b)      for (int (i) = (a); (i) < (b); ++(i))
#define rrep(i, b)          for (int (i) = (b) - 1; (i) >= 0; --(i))
#define rrepab(i, a, b)     for (int (i) = (b) - 1; (i) >= (a); --(i))
#define vi                  vector<int>
#define vl                  vector<ll>
#define vii                 vector<pair<int, int>>
#define vvi                 vector<vector<int>>
#define vvii                vector<vector<pair<int, int>>>
#define ms(a, p)            memset((a), (p), sizeof(a))
#define pb                  push_back
#define x                   first
#define y                   second
#define prev                prev28
#define next                next28
#define sqr(x)              ((x) * (x))
#define sqrt(x)             sqrt((double)(x))
#define pow(x, y)           pow(1.0 * (x), (y))
#define pow2(y)             (1LL<<(y))
#define pow2_(y)            (2LL<<(y))
#define testbit(x, y)       (((x)>>(y))&1)
#define ispow2(x)           ((x) != 0 && ((x)&((x) - 1)) == 0)
#define bitcount(x)         __builtin_popcountll(x)
ll rightmostPower2(ll x) {
    return x ^ (x & (x - 1));
}
ll largestPower2LE(ll n)
{
    n = n | (n >> 1);
    n = n | (n >> 2);
    n = n | (n >> 4);
    n = n | (n >> 8);
    n = n | (n >> 16);
    n = n | (n >> 32);
    return (n + 1) >> 1;

}
#define INF                    1e+9
#define INFLL                  1e+18LL
#define INTINF                 (~0U>>1)
#define INTINFLL               (~0ULL>>1)

double getUserTime() {
    timeval tv;
    gettimeofday(&tv, 0);
    return tv.tv_sec + tv.tv_usec * 1e-6;
}
#define USERTIME()          ({ double result = getUserTime(); fprintf(stderr, "User Time = %.6lf\n", result); \
                            fflush(stderr); result; })
#define TOTALTIME()         ({ double result = (double) clock() / CLOCKS_PER_SEC; \
                            fprintf(stderr, "User+System Time = %.6lf\n", result); fflush(stderr); result; })
#define DOJOB(job)          ({ double __begin = clock(); errno = 0; int result = (job); \
                            fprintf(stderr, "User+System Time = %.6lf\n", ((double) clock() - __begin) / CLOCKS_PER_SEC); \
                            fflush(stderr); result; })

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fastIO cin.sync_with_stdio(false), cin.tie(0)
#define noFastIO cin.sync_with_stdio(true), cin.tie(cout)
template<typename T>
void _R(T &x) { cin >> x; }
template<typename T>
void _R(vector<T> &x) { for (int i = 0; i < x.size(); ++i) _R(x[i]); }
template<typename T, size_t N>
void _R(T (&x)[N]) { for (int i = 0; i < N; ++i) { _R(x[i]); } }
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf(LLD, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<typename T, size_t N>
void R(T (&x)[N], int n) { for (int i = 0; i < n; ++i) _R(x[i]); }
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}
template<typename T>
void _P(const T &x ) { cout << x; }
void _P(const int &x ) { printf("%d", x); }
void _P(const ll &x ) { printf(LLD, x); }
template<typename T>
void _P(const vector<T> &x ) {
    for (auto i = x.cbegin(); i != x.cend(); i++) {
        if (i != x.cbegin()) putchar(' ');
        _P(*i);
    }
}
template<typename T>
void _P(vector<T> &x) {
    for (int i = 0; i < (int) x.size() - 1; ++i) { _P(x[i]); printf(" "); }
    if (x.size() >= 1) {
        _P(x[(int) x.size() - 1]);
        puts("");
    }
}
void P() {}
template<typename T, size_t N>
void P(T (&x)[N], int n) {
    for (int i = 0; i < n - 1; ++i) { _P(x[i]); printf(" "); }
    if (n >= 1) {
        _P(x[n - 1]);
        puts("");
    }
}
template<typename T, typename... U>
void P(const T& head, const U&... tail) {
    _P(head);
    if (sizeof...(tail)) {
        printf(" ");
        P(tail...);
    } else {
        puts("");
    }
}
#ifdef LOCAL
template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s << "[";
    for (auto it = b; it != e; ++it) s << (it == b ? "" : " ") << *it;
    s << "]";
    return s;
}
ostream& operator <<(ostream &s, const char *st) { return s << string(st); }
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) { return s << "(" << p.first << "," << p.second << ")"; }
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) { return _out(s, all(c)); }
template<typename T, size_t N>
ostream& operator <<(ostream &s, const array<T,N> &c) { return _out(s, all(c)); }
template<typename T>
ostream& operator <<(ostream &s, const set<T> &c) { return _out(s, all(c)); }
template<typename A, typename B>
ostream& operator <<(ostream &s, const map<A,B> &c) { return _out(s, all(c)); }
template<typename T, size_t N >
ostream& operator <<(ostream &s, T (&c)[N]) { return _out(s, &c[0], &c[N]); }
template<typename T>
void _show(T&& head) { cerr << head << endl; }
template<typename T, typename... Args>
void _show(T&& head, Args&&... tail ) {
    cerr << head;
    fprintf(stderr, ", ");
    _show(tail...);
}
#define show(...) do { fprintf(stderr, "%s:%d - \"%s\" - ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__); _show(__VA_ARGS__); } while (0)
#else
#define show(...)
#endif

template<typename U>
void SORT(U& a) { sort(begin(a), end(a)); }
template<typename T, size_t N>
void SORT(T (&a)[N], int n) { sort(&a[0], &a[n]); }
template<typename U>
void SORTR(U& a) { sort(begin(a), end(a), [](typename U::value_type x, typename U::value_type y) { return x > y; }); }
template<typename T, size_t N>
void SORTR(T (&a)[N], int n) { sort(&a[0], &a[n], [](T x, T y) { return x > y; }); }

const double PI = acos(-1.0);
inline void inc(int& a, int b, int p) { a += b; if (a >= p) a -= p; }
inline void dec(int& a, int b, int p) { a -= b; if (a < 0) a += p; }
inline int mul(int a, int b, int p) { return (ll) a * b % p; }
template<typename T>
inline bool mx(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
inline bool mn(T& a, T b) { if (b < a) { a = b; return true; } return false; }

int a[100000 + 2];

int solve(int testId) {

    int n, x;

    R(n, x);
    ll res = 0;
    rep(i,n) {
        R(a[i]);
    }
    repab(i,1,n) {
        if (a[i] + a[i-1] > x) {
            int d = a[i] + a[i-1] - x;
            res += d;
            a[i] -= d;
            if (a[i] < 0) {
                a[i-1] += a[i];
                a[i] = 0;
            }
        }
    }
    P(res);

    return EXIT_SUCCESS;
}

int main() {
    fastIO;
    #ifdef LOCAL
        int numTests = 3;
        rep(i, numTests) {
            int exitStatus = DOJOB(solve(i));
            if (exitStatus != EXIT_SUCCESS) return exitStatus;
        }
        return EXIT_SUCCESS;
    #else
        return solve(0);
    #endif
}


Measured memory_bytes: 640