#include <bits/stdc++.h>
using namespace std;
long long a[100005] = {0}, b[100005] = {0};
long long dp1[100005] = {0}, dp2[100005] = {0};
int main() {
  int n, i;
  long long c, sum = 0, ans = 0, t, x, y, f;
  cin >> n >> c;
  for (i = 1; i <= n; i++) {
    scanf("%lld %lld", &b[i], &a[i]);
  }
  dp1[0] = 0;
  dp2[0] = -c;
  x = a[1] - b[1];
  y = a[n] - c + b[n];
  for (i = 1; i <= n; i++) {
    dp1[i] = dp1[i - 1] + a[i] - b[i] + b[i - 1];
    ans = max(ans, dp1[i]);
    dp2[i] = dp2[i - 1] + a[n - i + 1] + b[n - i + 1] - b[n - i + 2];
    ans = max(ans, dp2[i]);
  }
  f = 0;
  for (i = 1; i < n; i++) {
    t = dp1[i] - b[i] + a[n] - c + b[n];
    if (t > y) {
      f = i;
      y = t;
    }
  }
  if (f) {
    sum = y + c - b[n];
    t = sum - c + b[n];
    ans = max(ans, t);
    for (i = n - 1; i > f; i--) {
      sum += a[i];
      t = sum - c + b[i];
      ans = max(ans, t);
    }
  }
  f = 0;
  for (i = 1; i < n; i++) {
    t = dp2[i] - c + b[n - i + 1] + a[1] - b[1];
    if (t > x) {
      f = i;
      x = t;
    }
  }
  if (f) {
    sum = x + b[1];
    t = sum - b[1];
    ans = max(ans, t);
    for (i = 2; i < n - f; i++) {
      sum += a[i];
      t = sum - b[i];
      ans = max(ans, t);
    }
  }
  cout << ans << endl;
}
