#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double epsilon = 1e-7;
long long int ma(long long int x, long long int y) {
  if (x > y) return x;
  return y;
}
long long int x[100000];
long long int v[100000];
long long int fo[100000];
long long int ba[100000];
long long int f2[100000];
long long int b2[100000];
int main(void) {
  int n;
  long long int c;
  scanf("%d %lld", &n, &c);
  long long int vsum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &x[i], &v[i]);
    vsum += v[i];
    fo[i] = vsum - x[i];
    f2[i] = vsum - x[i] - x[i];
  }
  vsum = 0;
  for (int i = n - 1; i >= 0; i--) {
    vsum += v[i];
    ba[i] = vsum - c + x[i];
    b2[i] = vsum - c - c + x[i] + x[i];
  }
  long long int fm = 0;
  long long int bm = 0;
  int ff = -1;
  int bb = -1;
  for (int i = 0; i < n; i++) {
    if (i != 0 && i != n - 1)
      if (fm < fo[i] &&
          (fo[i] + b2[i + 1] >= fo[i - 1] + b2[i] || b2[i] <= 0)) {
        fm = fo[i];
        ff = i;
      } else if (i == 0)
        if (fm < fo[i] && (fo[i] + b2[i + 1] >= ba[i] || ba[i] <= 0)) {
          fm = fo[i];
          ff = i;
        } else if (fm < fo[i] && (fo[i] >= fo[i - 1] + b2[i] || b2[i] <= 0)) {
          fm = fo[i];
          ff = i;
        }
  }
  for (int i = 0; i < n; i++) {
    if (i != 0 && i != n - 1)
      if (bm < ba[i] &&
          (ba[i] + f2[i - 1] >= ba[i + 1] + f2[i] || f2[i] <= 0)) {
        bm = ba[i];
        bb = i;
      } else if (i == 0)
        if (bm < ba[i] && ba[i] >= ba[i + 1] + f2[i]) {
          bm = ba[i];
          bb = i;
        } else if (bm < ba[i] && (ba[i] + f2[i - 1] >= fo[i] || fo[i] <= 0)) {
          bm = ba[i];
          bb = i;
        }
  }
  if (fm + bm == 0)
    printf("0\n");
  else {
    long long int f2m = 0;
    long long int b2m = 0;
    for (int i = 0; i < bb; i++) {
      f2m = ma(f2m, f2[i]);
    }
    for (int i = n - 1; i > ff; i--) {
      b2m = ma(b2m, b2[i]);
    }
    printf("%lld\n", ma(fm + b2m, bm + f2m));
  }
  return 0;
}
