#include <cstdio>
#include <cassert>

int main()
{
  freopen("fitness.in", "r", stdin);
  freopen("fitness.out", "w", stdout);
  int n, k, A, B;
  scanf("%d%d", &n, &k);
  assert(1 <= n && n <= 100);
  assert(1 <= k && k <= 1000);
  A = k, B = 0;
  for (int i = 0; i < n; i++)
  {
    int a, b;
    scanf("%d%d", &a, &b);
    assert(0 <= a && 0 <= b);
    assert(a + b <= k);
    if (b >= B)
      A -= b - B, B = b;
    else
      if (a >= B - b)
        A += B - b, B = b;
      else
        B -= a, A += a;
  }
  printf("%d\n", A);
  return 0;
}
