#include <bits/stdc++.h>
using namespace std;
int n, all, a[400012];
long long C, b[400012], s[400012], c[400012];
inline void cha(int x, long long v) {
  for (++x; x; x &= (x - 1)) c[x] = max(c[x], v);
}
inline long long Ask(int x) {
  long long res = c[0];
  for (++x; x <= n + 1; x += x & (-x)) res = max(res, c[x]);
  return res;
}
int main() {
  memset(c, 200, sizeof(c));
  scanf("%d%lld", &n, &C);
  all = (n << 1) - 1;
  int i, l = 0, r;
  for (i = 1; i <= all; i++)
    scanf("%d", &a[i]), a[i] = min(1ll * a[i], C), s[i] = s[i - 1] + a[i];
  cha(0, 0);
  for (i = 1; i <= n; i++) {
    r = (i << 1) - 1;
    while ((l < r) && (s[r] - s[l] >= C)) l += 2;
    if (l <= r) b[i] = max(b[i - 1], Ask(l >> 1) + s[r]);
    if (l && (s[r] - s[l - 2] >= C)) b[i] = max(b[i], b[(l - 2) >> 1] + C);
    cha(i, b[i] - s[i << 1]);
  }
  printf("%lld", b[n]);
  return 0;
}
