#include <bits/stdc++.h>
using namespace std;
const int N = 400005;
int n;
long long c, a[N], b[N], result = 0;
long long tsum[4 * N], tmax[4 * N];
void update(int v, int tl, int tr, int pos, long long x, long long y) {
  if (tl == tr) {
    tsum[v] = x - y;
    tmax[v] = max(0LL, tsum[v]);
    return;
  }
  int tm = (tl + tr) / 2;
  if (pos <= tm) {
    update(2 * v, tl, tm, pos, x, y);
  } else {
    update(2 * v + 1, tm + 1, tr, pos, x, y);
  }
  tsum[v] = tsum[2 * v] + tsum[2 * v + 1];
  tmax[v] = max(tmax[2 * v + 1], tsum[2 * v + 1] + tmax[2 * v]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> c;
  n = 2 * n - 1;
  for (int i = (1); i <= (n); ++i) cin >> a[i], a[i] = min(a[i], c);
  int l = 1;
  long long sum = 0;
  for (int i = 1; i <= n; i += 2) {
    b[i] = a[i];
    sum += a[i];
    while (sum > c) {
      sum -= a[l];
      a[l] = max(0LL, c - sum);
      update(1, 1, n, l, a[l], b[l]);
      sum += a[l];
      if (sum <= c) break;
      l += 2;
    }
    update(1, 1, n, i, a[i], b[i]);
    b[i] += tmax[1];
    sum -= a[i];
    a[i] += a[i + 1];
    a[i] = min(a[i], c);
    sum += a[i];
    while (sum > c) {
      sum -= a[l];
      a[l] = max(0LL, c - sum);
      update(1, 1, n, l, a[l], b[l]);
      sum += a[l];
      if (sum <= c) break;
      l += 2;
    }
    update(1, 1, n, i, a[i], b[i]);
    result += b[i];
  }
  cout << result << '\n';
  return 0;
}
