#include <bits/stdc++.h>
using namespace std;
template <class T>
class MonotonicQueue {
  deque<T> maxQ;
  queue<T> Q;

 public:
  void push(T x) {
    while (!maxQ.empty() && x > maxQ.back()) maxQ.pop_back();
    maxQ.push_back(x);
    Q.push(x);
  }
  void pop() {
    if (Q.front() == maxQ.front()) maxQ.pop_front();
    Q.pop();
  }
  T getMax() { return maxQ.front(); }
  bool empty() { return Q.empty(); }
};
const int MAX = 200200;
const long long inf = 1e18;
long long a[MAX], b[MAX];
long long s[MAX];
long long x[MAX], sx[MAX];
int main(void) {
  int N;
  long long C;
  scanf("%d %lld", &N, &C);
  for (int i = (0); i < (N); ++i) {
    scanf("%lld", &a[i]);
    if (i < N - 1) scanf("%lld", &b[i]);
  }
  for (int i = (0); i < (N); ++i) a[i] = min(a[i], C);
  for (int i = (0); i < (N - 1); ++i) b[i] = min(b[i], C);
  if (N == 1) {
    printf("%lld\n", a[0]);
    return 0;
  }
  s[0] = 0;
  for (int i = (0); i < (N); ++i) s[i + 1] = s[i] + a[i] + b[i];
  auto f = [&](long long x0) {
    long long total = x0;
    x[0] = x0;
    sx[1] = x0;
    int l = 0;
    MonotonicQueue<long long> Q;
    Q.push(sx[0] - s[0]);
    for (int i = 1; i < N; ++i) {
      long long cur = a[i];
      while (l < i && s[i] - s[l] + a[i] >= C) {
        l++;
        Q.pop();
      }
      if (!Q.empty()) {
        cur = max(cur, a[i] + s[i] - sx[i] + Q.getMax());
      }
      if (l - 1 >= 0) {
        cur = max(cur, C - (sx[i] - sx[l - 1]));
      }
      x[i] = cur;
      sx[i + 1] = sx[i] + x[i];
      Q.push(sx[i] - s[i]);
      total += cur;
    }
    return total;
  };
  long long lo = min(C, a[0]);
  long long hi = min(C, a[0] + b[0]);
  while (lo < hi) {
    long long mid = (lo + hi) / 2;
    if (f(mid) < f(mid + 1))
      hi = mid;
    else
      lo = mid + 1;
  }
  printf("%lld\n", f(lo));
  return 0;
}
