#include <bits/stdc++.h>
#define pb push_back
#define ll long long 
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    for(int T = 0; T < t ; T++){
        ll n, x;
       cin >> n >> x;
       ll a[n], ans = 0;
       for(int i = 0; i < n; i++)
            cin >> a[i];
       if(a[0] > x){
           ans += a[0] - x;
           a[0] = x;
       }
       for(int i = 1; i < n; i++){
           if(a[i] + a[i - 1] > x){
                ans += a[i] + a[i -1] - x;
               a[i] = x - a[i - 1];
           }
       }
       std::cout << ans  << std::endl;
    }
    return 0;
}
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, x;
	cin >> n >> x;
	VI a(n);
	REP(i, n) { cin >> a[i]; }

	ll result = 0;
	REP(i, n - 1) {
		if(a[i] + a[i + 1] > x) {
			int d = a[i] + a[i + 1] - x;
			if(a[i + 1] < d) {
				a[i] -= d - a[i + 1];
				a[i + 1] = 0;
			} else {
				a[i + 1] -= d;
			}
			result += d;
		}
	}

	cout << result << endl;
	return 0;
}
