#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                    \
  for (int i = 0; i < (int)(n); i++) \
    ;

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;
  cin >> n;
  long x;
  cin >> x;
  vector<long> a(n);
  for (long &x : a) {
    cin >> x;
  }
  long count = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) + a.at(i + 1) > x) {
      long count_plus = min(a.at(i) + a.at(i + 1) - x, a.at(i + 1));
      count += count_plus;
      a.at(i + 1) -= count_plus;
      if (a.at(i + 1) == 0) {
        long count_plus = a.at(i) - x;
        count += count_plus;
        a.at(i) -= count_plus;
      }
    }
  }
  cout << count << endl;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp

int n;
int A[100005];
int cnt;

static int par(int p, int r) {
    int i = p - 1;
    int x = A[r];
    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[j], A[i]);
        }
    }
    swap(A[r], A[i+1]);
    return i+1;
}

int main() {
    cin >> n;
    REP(i, n) cin >> A[i];
    int q = par(0, n-1);

    REP(i, n) {
        if (i) cout << " ";
        if (i == q) cout << "[";
        cout << A[i];
        if (i == q) cout << "]";
    }
    cout << "\n";
    return 0;
}

