#include <bits/stdc++.h>
using namespace std;
int n;
long long dp[200005], C, a[200005], b[200005];
;
long long ruia[200005], ruib[200005];
long long seg[(1 << 19)] = {};
void update(int k, long long a) {
  k += (1 << 19) / 2 - 1;
  seg[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);
  }
}
long long query(int a, int b, int k, int l, int r) {
  if (r < a || b < l || a > b) return -1e18;
  if (a <= l && r <= b)
    return seg[k];
  else {
    long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = query(a, b, k * 2 + 2, (l + r) / 2 + 1, r);
    return max(vl, vr);
  }
}
int main() {
  cin >> n >> C;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    ruia[i] = ruia[i - 1] + a[i];
    if (i != n) {
      scanf("%lld", &b[i]);
      ruib[i] = ruib[i - 1] + b[i];
    }
  }
  dp[0] = 0;
  fill(seg, seg + (1 << 19), -1e18);
  update(0, ruia[n] + ruib[n - 1]);
  for (int i = 1; i <= n; i++) {
    dp[i] = max(dp[i], dp[i - 1] + min(C, a[i]));
    if (a[i] >= C) continue;
    int lb = -1, ub = i - 1;
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2;
      long long SUM = ruia[i] - ruia[mid];
      SUM += ruib[i - 1] - ruib[mid];
      if (SUM >= C)
        lb = mid;
      else
        ub = mid;
    }
    if (lb >= 0) {
      dp[i] = max(dp[i], dp[lb] + C);
    }
    long long val = query(lb + 1, i - 2, 0, 0, (1 << 18) - 1);
    dp[i] = max(dp[i], val - (ruia[n] - ruia[i]) - (ruib[n - 1] - ruib[i - 1]));
    update(i, dp[i] + ruia[n] - ruia[i] + ruib[n - 1] - ruib[i]);
  }
  cout << dp[n] << endl;
}
