#include <bits/stdc++.h>
using namespace std;
long long n, arr[(1 << 20)], ans[(1 << 20)];
long long c;
long long fromR[(1 << 20)], leftC[(1 << 20)];
long long k = 19, it[(1 << 22)], toAdd[(1 << 22)];
void lazy(long long x) {
  if (x >= (1 << k)) {
    return;
  }
  it[x * 2] += toAdd[x];
  it[x * 2 + 1] += toAdd[x];
  toAdd[x * 2] += toAdd[x];
  toAdd[x * 2 + 1] += toAdd[x];
  toAdd[x] = 0;
}
long long getMin(long long l, long long r, long long ll = 0,
                 long long rr = (1 << k), long long ind = 1) {
  lazy(ind);
  if (l <= ll && rr <= r) {
    return it[ind];
  }
  if (r <= ll || rr <= l) {
    return 1LL << 42;
  }
  return min(getMin(l, r, ll, (ll + rr) / 2, ind * 2),
             getMin(l, r, (ll + rr) / 2, rr, ind * 2 + 1));
}
void inc(long long l, long long r, long long val, long long ll = 0,
         long long rr = (1 << k), long long ind = 1) {
  lazy(ind);
  if (l <= ll && rr <= r) {
    it[ind] += val;
    toAdd[ind] += val;
    return;
  }
  if (r <= ll || rr <= l) {
    return;
  }
  inc(l, r, val, ll, (ll + rr) / 2, ind * 2);
  inc(l, r, val, (ll + rr) / 2, rr, 1 + ind * 2);
  it[ind] = min(it[ind * 2], it[ind * 2 + 1]);
}
void setVal(long long x, long long val, long long ll = 0,
            long long rr = (1 << k), long long ind = 1) {
  lazy(ind);
  if (x == ll && rr == x + 1) {
    it[ind] = val;
    return;
  }
  if (x + 1 <= ll || rr <= x) {
    return;
  }
  setVal(x, val, ll, (ll + rr) / 2, ind * 2);
  setVal(x, val, (ll + rr) / 2, rr, ind * 2 + 1);
  it[ind] = min(it[ind * 2], it[ind * 2 + 1]);
}
long long getVal(long long x) { return getMin(x, x + 1); }
inline void add(long long ind, long long val) {
  long long j = ind;
  long long d = val;
  if (j % 2) {
    long long nx = d;
    if (leftC[j / 2] >= nx) {
      leftC[j / 2] -= nx;
      nx = 0;
    } else {
      nx -= leftC[j / 2];
      leftC[j / 2] = 0;
      setVal(j, nx);
      fromR[j] = nx;
      if (leftC[j / 2 + 1] >= nx) {
        leftC[j / 2 + 1] -= nx;
      } else {
        long long cd = nx - leftC[j / 2 + 1];
        leftC[j / 2 + 1] = 0;
        ans[j / 2 + 1] += cd;
      }
    }
  } else {
    if (leftC[j / 2] >= d) {
      leftC[j / 2] -= d;
    } else {
      long long cd = d - leftC[j / 2];
      leftC[j / 2] = 0;
      ans[j / 2] += cd;
    }
  }
}
inline void rem(long long ind, long long val) {
  if (ind % 2) {
    leftC[ind / 2 + 1] += getVal(ind);
    leftC[ind / 2] += val - getVal(ind);
    setVal(ind, 0);
    fromR[ind] = 0;
  } else {
    leftC[ind / 2] += val;
  }
}
vector<pair<int, long long> > els;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  for (long long i = 0; i < (1 << k); i += 2) {
    setVal(i, 1LL << 42);
  }
  cin >> n >> c;
  for (long long i = 0; i < 2 * n - 1; i++) {
    cin >> arr[i];
    arr[i] = min(1LL * arr[i], c);
    if (i % 2 == 0) {
      ans[i / 2] = arr[i];
      leftC[i / 2] = arr[i];
    }
  }
  long long cSum = 0;
  long long f = 0;
  for (; f < 2 * n - 1 && cSum < c; f++) {
    long long d = arr[f];
    if (cSum + arr[f] > c) {
      d = c - cSum;
    }
    add(f, d);
    els.push_back(make_pair(f, d));
    cSum += d;
  }
  for (long long s = 2; s < 2 * n - 1; s += 2) {
    bool b = 1;
    while (els.size() && (b || (els.back().first % 2 == 0))) {
      cSum -= els.back().second;
      rem(els.back().first, els.back().second);
      f--;
      els.pop_back();
      b = 0;
    }
    if (els.size() > 4) {
      cSum -= arr[s - 2];
      cSum -= arr[s - 1];
    } else {
      while (els.size()) {
        cSum -= els.back().second;
        rem(els.back().first, els.back().second);
        f--;
        els.pop_back();
      }
    }
    long long minR = 1LL << 42;
    minR = getMin(s - 1, f);
    inc(s - 1, f, -minR);
    if (els.size()) {
      leftC[els.back().first / 2 + 1] += minR;
    }
    f = max(f, s);
    for (; f < 2 * n - 1 && cSum < c; f++) {
      long long d = arr[f];
      if (cSum + arr[f] > c) {
        d = c - cSum;
      }
      add(f, d);
      els.push_back(make_pair(f, d));
      cSum += d;
    }
  }
  long long cc = 0;
  for (long long i = 0; i < n; i++) {
    cc += ans[i];
  }
  cout << cc << "\n";
  return 0;
}
