#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 4e5 + 10;
long long a[N], b[N];
long long suma[N], sumb[N];
multiset<long long> Set;
multiset<long long>::iterator it;
inline long long read() {
  long long x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') flag = -1, ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch - '0'), ch = getchar();
  return x * flag;
}
int main() {
  int n = read();
  long long C = read();
  for (int i = (2), iend = (2 * n); i <= iend; i++)
    suma[i] = suma[i - 1] + (a[i] = read());
  int pos = 2;
  long long Max = -INF;
  Set.insert(0);
  for (int i = 2; i <= 2 * n; i += 2) {
    while (pos <= i && suma[i] - suma[pos - 1] >= C) {
      it = Set.lower_bound(sumb[pos - 2] - suma[pos - 1]);
      Set.erase(it), chkmax(Max, sumb[pos - 2]), pos += 2;
    }
    if (Set.size()) chkmax(b[i], suma[i] + *(--Set.end()) - sumb[i - 2]);
    chkmax(b[i], C + Max - sumb[i - 2]);
    sumb[i] = sumb[i - 2] + b[i];
    Set.insert(sumb[i] - suma[i + 1]);
  }
  long long ans = 0;
  for (int i = 2; i <= 2 * n; i += 2) ans += b[i];
  printf("%lld\n", ans);
  return 0;
}
