#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000001;
const long long LINF = 1000000000000000001LL;
struct MinTree {
  const long long INIT = LINF;
  long long combine(const long long &a, const long long &b) {
    return min(a, b);
  }
  vector<long long> T;
  int p = 1;
  MinTree(int n) {
    while (p < n) p *= 2;
    T.resize(2 * p - 1, INIT);
  }
  int par(int x) { return (x - 1) / 2; }
  void set(int l, long long v) {
    l += p - 1;
    T[l] = v;
    while (l > 0) {
      l = par(l);
      T[l] = combine(T[2 * l + 1], T[2 * l + 2]);
    }
  }
  long long query(int l, int r) {
    l += p - 1;
    r += p - 1;
    long long ans = combine(T[l], T[r]);
    while (par(l) != par(r)) {
      if (l % 2 == 1) ans = combine(ans, T[l + 1]);
      if (r % 2 == 0) ans = combine(ans, T[r - 1]);
      l = par(l);
      r = par(r);
    }
    return ans;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  long long c;
  cin >> n >> c;
  vector<long long> a(n), b(n, 0);
  for (int i = (0); i <= (n - 1); ++i) {
    cin >> a[i];
    if (i < n - 1) {
      cin >> b[i];
    }
  }
  vector<long long> abPref(n + 1, 0);
  for (int i = (0); i <= (n - 1); ++i) {
    abPref[i + 1] = abPref[i] + a[i] + b[i];
  }
  vector<long long> dp(n + 1, LINF);
  MinTree tree(n + 1);
  dp[0] = 0;
  tree.set(0, 0);
  for (int i = (0); i <= (n - 1); ++i) {
    long long here = LINF;
    int l = -1, r = i + 1;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (abPref[i + 1] - abPref[mid] - b[i] <= c) {
        r = mid;
      } else {
        l = mid;
      }
    }
    if (r <= i) {
      here = b[i] + tree.query(r, i);
    }
    if (l > -1) {
      here = min(here, dp[l] + abPref[i + 1] - abPref[l] - c);
    }
    dp[i + 1] = here;
    tree.set(i + 1, here);
  }
  cout << abPref.back() - dp.back();
  return 0;
}
