#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline void priv(vector<int> a) {
  for (int i = 0; i < ((int)(a).size()); ++i)
    printf("%d%c", a[i], i == (int)(a).size() - 1 ? '\n' : ' ');
}
template <typename T>
istream& operator>>(istream& i, vector<T>& v) {
  for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];
  return i;
}
template <typename T>
string join(const vector<T>& v) {
  stringstream s;
  for (int i = 0; i < ((int)(v).size()); ++i) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
template <typename T1, typename T2>
istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& v) {
  return o << v.first << "," << v.second;
}
const int MX = 200005, INF = 1001001001;
const long long int LINF = 1e18;
const double eps = 1e-10;
int n;
long long int m;
struct SQ {
  typedef pair<long long int, long long int> TP;
  deque<TP> q;
  void add(long long int i, long long int x) {
    while ((int)(q).size() && q.back().first >= x) q.pop_back();
    q.push_back(TP(x, i));
  }
  long long int get(long long int i) {
    while ((int)(q).size() > 1 && i - q[0].second > m) {
      if (q[0].first + ((i - q[0].second) - m) < q[1].first) break;
      q.pop_front();
    }
    if ((int)(q).size()) return q[0].first + max(0ll, (i - q[0].second) - m);
    return LINF;
  }
};
int main() {
  scanf("%d%I64d", &n, &m);
  vector<long long int> a(n);
  vector<long long int> b(n);
  for (int i = 0; i < (n); ++i) {
    scanf("%I64d", &a[i]);
    a[i] = min(a[i], m);
    if (i != n - 1) {
      scanf("%I64d", &b[i]);
      b[i] = min(b[i], m);
    }
  }
  long long int ans = 0;
  vector<long long int> x(n);
  x[0] = a[0];
  SQ q;
  long long int s = a[0], t = 0;
  q.add(0, 0);
  for (int i = 0; i < (n - 1); ++i) {
    s += b[i];
    t += x[i];
    q.add(s, s - t);
    s += a[i + 1];
    x[i + 1] = (s - t) - q.get(s);
  }
  for (int i = 0; i < (n); ++i) ans += x[i];
  cout << ans << endl;
  return 0;
}
