#include <bits/stdc++.h>
using namespace std;
set<pair<long long, long long> > S;
const long long N = 200005;
long long T, n, c, a[N], b[N], f[N];
signed main() {
  memset(f, 0, sizeof f);
  S.clear();
  long long ans = 0;
  scanf("%lld%lld", &n, &c);
  for (long long i = 1; i < 2 * n; i++)
    if (i & 1)
      scanf("%lld", &a[i / 2 + 1]);
    else
      scanf("%lld", &b[i / 2]);
  for (long long i = 1; i <= n; i++) a[i] = min(a[i], c), a[i] += a[i - 1];
  for (long long i = 1; i <= n; i++) b[i] = min(b[i], c), b[i] += b[i - 1];
  long long now = 0;
  f[1] = ans = a[1];
  S.insert(make_pair(-a[1] - b[1] + f[1], 1));
  S.insert(make_pair(0, 0));
  for (long long i = 2; i <= n; i++) {
    while (now < i && a[i] - a[now] + b[i - 1] - b[now] >= c) {
      S.erase(make_pair(-a[now] - b[now] + f[now], now));
      now++;
    }
    if (S.begin() != S.end()) {
      set<pair<long long, long long> >::iterator it = S.end();
      it--;
      f[i] = a[i] + b[i - 1] - f[i - 1] + (*it).first;
    } else
      f[i] = 0;
    if (now) f[i] = max(f[i], c - f[i - 1] + f[now - 1]);
    ans += f[i];
    f[i] += f[i - 1];
    S.insert(make_pair(-a[i] - b[i] + f[i], i));
  }
  printf("%lld\n", ans);
  return 0;
}
