#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x >= 0 ? x : -x;
}
template <class T>
T sqr(T x) {
  return x * x;
}
int n;
long long c;
vector<long long> a;
struct Magic {
  long long c;
  long long plus, minus;
  long long best_c;
  set<pair<long long, long long> > pm;
  set<pair<long long, long long> > sm;
  Magic(long long c) : c(c) {
    plus = 0;
    minus = 0;
    best_c = c;
  }
  void add(long long x) {
    x -= plus;
    pm.insert(pair<long long, long long>(x, -minus));
    sm.insert(pair<long long, long long>(x + minus, -minus));
    update();
  }
  void inc(long long x) {
    plus += x;
    update();
  }
  void dec(long long x) {
    minus += x;
    update();
  }
  long long max() {
    long long best = c - best_c - minus;
    if (((int)(sm).size())) {
      long long sum = sm.rbegin()->first;
      sum += plus;
      sum -= minus;
      best = std::max<long long>(best, sum);
    }
    return best;
  }
  void update() {
    while (((int)(pm).size()) && pm.rbegin()->first + plus >= c) {
      pair<long long, long long> entry = *pm.rbegin();
      pm.erase(entry);
      sm.erase(
          pair<long long, long long>(entry.first - entry.second, entry.second));
      best_c = min(best_c, entry.second);
    }
  }
};
int main() {
  scanf("%d", &n);
  cin >> c;
  a.resize(2 * n - 1);
  for (int i = 0; i < ((int)(a).size()); ++i) {
    int x;
    scanf("%d", &x);
    a[i] = x;
  }
  Magic magic(c);
  long long res = 0;
  for (int i = 0; i < ((int)(a).size()); ++i) {
    if (i % 2 == 1) {
      magic.inc(a[i]);
      continue;
    }
    magic.add(0);
    magic.inc(a[i]);
    long long cur = magic.max();
    res += cur;
    magic.dec(cur);
  }
  cout << res << "\n";
  return 0;
}
