#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, C;
  cin >> n >> C;
  long long s[n];
  long long d[n];
  d[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    s[i] = min(C, s[i]);
    if (i < n - 1) cin >> d[i];
  }
  d[n - 1] = 0;
  long long a[n];
  multiset<long long> best;
  best.insert(0);
  long long z = 0;
  int cur = 0;
  long long curnsum = 0;
  long long ntotal = 0;
  long long atotal = 0;
  vector<long long> bestv, atot;
  bestv.push_back(0);
  atot.push_back(0);
  for (int i = 0; i < n; i++) {
    a[i] = 0;
    ntotal += s[i];
    if (i > 0) ntotal += d[i - 1];
    curnsum += s[i];
    if (i > 0) curnsum += d[i - 1];
    while (curnsum > C) {
      best.erase(best.find(bestv[cur]));
      curnsum -= s[cur];
      curnsum -= d[cur];
      cur++;
    }
    if (cur > 0) {
      a[i] = max(a[i], C - atot[i] + atot[cur - 1]);
    }
    if (!best.empty()) {
      a[i] = max(a[i], -*best.begin() + ntotal - atotal);
    }
    z -= s[i];
    z -= d[i];
    z += a[i];
    best.insert(-z);
    bestv.push_back(-z);
    atotal += a[i];
    atot.push_back(atotal);
  }
  cout << atotal << endl;
}
