#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
using ld = long double;
constexpr int nax = 1000 * 1000 + 105;
constexpr int infty = 1000 * 1000 * 1000 + 5;
constexpr int mod = 1000 * 1000 * 1000 + 7;
struct Drzewo {
  ll wartosc;
  ll ile;
  ll spusc;
};
Drzewo drz[nax * 2];
int n2;
void Spusc(int w) {
  if (drz[w].spusc) {
    drz[w].wartosc += drz[w].spusc;
    if (w < n2) {
      drz[w * 2].spusc += drz[w].spusc;
      drz[w * 2 + 1].spusc += drz[w].spusc;
    }
    drz[w].spusc = 0;
  }
}
ll MaxWartosc_(int w, int p, int k, int a, int b) {
  if (k < a or b < p) return 0;
  Spusc(w);
  if (a <= p and k <= b) {
    return drz[w].wartosc;
  }
  return max(MaxWartosc_(w * 2, p, (p + k) / 2, a, b),
             MaxWartosc_(w * 2 + 1, (p + k + 1) / 2, k, a, b));
}
ll MaxWartoscWiecejNizZero2(int a, int b) {
  return max(0ll, MaxWartosc_(1, 0, n2 - 1, a, b));
}
void DodajWartosc_(int w, int p, int k, int a, int b, ll x) {
  if (k < a or b < p) return;
  Spusc(w);
  if (a <= p and k <= b) {
    drz[w].spusc += x;
    Spusc(w);
    return;
  }
  DodajWartosc_(w * 2, p, (p + k) / 2, a, b, x);
  DodajWartosc_(w * 2 + 1, (p + k + 1) / 2, k, a, b, x);
  drz[w].wartosc = max(drz[w * 2].wartosc, drz[w * 2 + 1].wartosc);
}
void DodajWartosc2(int w, ll x) { DodajWartosc_(1, 0, n2 - 1, 1, w, x); }
void DodajIle_(int w, int p, int k, int a, ll x) {
  if (!(p <= a and a <= k)) return;
  Spusc(w);
  drz[w].ile += x;
  if (p == k) {
    return;
  }
  DodajIle_(w * 2, p, (p + k) / 2, a, x);
  DodajIle_(w * 2 + 1, (p + k + 1) / 2, k, a, x);
}
void DodajIle2(int w, ll x) { DodajIle_(1, 0, n2 - 1, w, x); }
ll IleJest_(int w, int p, int k, int a, int b) {
  if (k < a or b < p) return 0;
  Spusc(w);
  if (a <= p and k <= b) {
    return drz[w].ile;
  }
  return IleJest_(w * 2, p, (p + k) / 2, a, b) +
         IleJest_(w * 2 + 1, (p + k + 1) / 2, k, a, b);
}
ll IleJest2(int a, int b) { return IleJest_(1, 0, n2 - 1, a, b); }
int n;
ll C;
ll jeden[nax], dwa[nax];
ll ile[nax];
ll wartosc[nax];
void DodajWartosc(int w, ll x) { DodajWartosc2(w, x); }
ll MaxWartoscWiecejNizZero(int a, int b) {
  ll result = MaxWartoscWiecejNizZero2(a, b);
  return result;
}
void DodajIle(int w, ll x) {
  DodajIle2(w, x);
  ile[w] += x;
}
ll IleJest(int a, int b) {
  ll result = IleJest2(a, b);
  return result;
}
void Algos() {
  ll potrzeba = 0ll;
  ll potrz_wsk = 1;
  for (int i = 1; i <= n; i++) {
    potrzeba += jeden[i];
    while (potrzeba > C) {
      potrzeba -= jeden[potrz_wsk];
      potrzeba -= dwa[potrz_wsk];
      potrz_wsk++;
    }
    if (potrz_wsk > 1) {
      const ll jest = IleJest(potrz_wsk - 1, i);
      if (jest < C) {
        DodajIle(i, C - jest);
        ile[i] = C - jest;
      }
    }
    DodajWartosc(i, jeden[i] - ile[i]);
    const ll roznica = MaxWartoscWiecejNizZero(potrz_wsk, i);
    assert(roznica >= 0);
    DodajIle(i, roznica);
    DodajWartosc(i, dwa[i] - roznica);
    potrzeba += dwa[i];
  }
}
int main() {
  scanf("%d%lld", &n, &C);
  n2 = 1;
  while (n2 <= n) n2 *= 2;
  for (int i = 1; i <= 2 * n - 1; i++) {
    ll x;
    scanf("%lld", &x);
    x = min(x, C);
    if (i % 2 == 1) {
      jeden[(i + 1) / 2] = x;
    } else {
      dwa[i / 2] = x;
    }
  }
  Algos();
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += ile[i];
  }
  debug() << " ["
          << "range(ile + 1, ile + n + 1)"
             ": "
          << (range(ile + 1, ile + n + 1)) << "] ";
  printf("%lld\n", sum);
  return 0;
}
