#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
bool debug = false;
int main() {
  long long n, c;
  cin >> n >> c;
  vector<long long> x(n), v(n);
  for (int i = 0; i < int(n); i++) {
    cin >> x[i] >> v[i];
  }
  vector<long long> r(n), l(n);
  for (int i = 0; i < int(n); i++) {
    if (i == 0) {
      r[i] = v[i];
      l[n - i - 1] = v[n - 1];
    } else {
      r[i] = r[i - 1] + v[i];
      l[n - i - 1] = l[n - i] + v[n - i - 1];
    }
  }
  vector<long long> R(n), L(n);
  long long ans = -9000000000000000000;
  for (int i = 0; i < int(n); i++) {
    ans = max(ans, max(r[i] - x[i], l[n - i - 1] - (c - x[n - i - 1])));
    R[i] = r[i] - x[i];
    r[i] -= (x[i] * 2);
    L[n - i - 1] = l[n - i - 1] - (c - x[n - i - 1]);
    l[n - i - 1] -= (c - x[n - i - 1]) * 2;
  }
  for (int i = (1); i < int(n); i++) {
    r[i] = max(r[i], r[i - 1]);
    R[i] = max(R[i], R[i - 1]);
    l[n - i - 1] = max(l[n - i - 1], l[n - i]);
    L[n - i - 1] = max(L[n - i - 1], L[n - i]);
  }
  ans = max(ans, l[0]);
  for (int i = (1); i < int(n - 1); i++) {
    ans = max(ans, r[i] + L[i + 1]);
    ans = max(ans, l[i] + R[i - 1]);
  }
  cout << max(ans, (long long)0) << endl;
  return 0;
}
