#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;
}
struct hoge {
  long long int fx, bx, v, f1, b1, f2, b2;
};
struct hoge arr[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", &arr[i].fx, &arr[i].v);
    vsum += arr[i].v;
    arr[i].f1 = vsum - arr[i].fx;
    arr[i].f2 = vsum - arr[i].fx * 2;
    arr[i].bx = c - arr[i].fx;
  }
  vsum = 0;
  for (int i = n - 1; i >= 0; i--) {
    vsum += arr[i].v;
    arr[i].b1 = vsum - arr[i].bx;
    arr[i].b2 = vsum - arr[i].bx * 2;
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = ma(ans, arr[i].f1);
    if (i == 0 || arr[i].f1 > arr[i - 1].f1) {
      int j = n - 1;
      while (arr[j].bx < arr[i].fx && i < j) {
        ans = ma(ans, arr[i].f1 + arr[j].b2);
        j--;
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    ans = ma(ans, arr[i].b1);
    if (i == n - 1 || arr[i].b1 > arr[i + 1].b1) {
      int j = 0;
      while (arr[j].fx < arr[i].bx && i > j) {
        ans = ma(ans, arr[i].b1 + arr[j].f2);
        j++;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
