#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = (long long)1000000007 * 1000000007;
int main() {
  int n;
  long long c;
  long long X, V;
  cin >> n >> c;
  int i;
  long long x[100000], v[100000];
  long long score1[100000], score2[100000], score3[100000], score4[100000];
  for (i = 0; i < n; i++) {
    cin >> X >> V;
    x[i] = X;
    v[i] = V;
  }
  score1[0] = v[0] - x[0];
  score2[0] = v[n - 1] - (c - x[n - 1]);
  score3[0] = v[0] - 2 * x[0];
  score4[0] = v[n - 1] - 2 * (c - x[n - 1]);
  for (i = 1; i < n; i++) {
    score1[i] = score1[i - 1] + v[i] - (x[i] - x[i - 1]);
    score2[i] = score2[i - 1] + v[n - 1 - i] - (x[n - i] - x[n - 1 - i]);
    score3[i] = score3[i - 1] + v[i] - 2 * (x[i] - x[i - 1]);
    score4[i] = score4[i - 1] + v[n - 1 - i] - 2 * (x[n - i] - x[n - 1 - i]);
  }
  long long ma1 = 0;
  long long ma2 = 0;
  int check1, check2;
  for (i = 0; i < n; i++) {
    if (score1[i] > ma1) {
      ma1 = score1[i];
      check1 = i;
    }
    if (score2[i] > ma2) {
      ma2 = score2[i];
      check2 = i;
    }
  }
  long long out = 0;
  if (ma1 == 0 && ma2 == 0) {
    cout << 0 << endl;
  } else if (ma1 > 0 || ma2 > 0) {
    if (ma1 > 0) {
      long long csum = 0;
      for (i = n - 1; i > check1; i--) {
        csum = max(csum, score4[n - 1 - i]);
      }
      out = max(out, csum + ma1);
    }
    if (ma2 > 0) {
      long long csum = 0;
      for (i = 0; i < n - 1 - check2; i++) {
        csum = max(csum, score3[i]);
      }
      out = max(out, csum + ma2);
    }
    cout << out << endl;
  }
  return 0;
}
