#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  long long N, C;
  cin >> N >> C;
  vector<long long> x(N), v(N);
  for (long long i = 0; i < N; ++i) {
    cin >> x[i] >> v[i];
  }
  long long c = 0;
  vector<long long> vcw(N), vccw(N), vcw0(N + 1), vccw0(N + 1);
  for (long long i = 0, cal = 0, pos = 0; i < N; ++i) {
    cal += v[i] - (x[i] - pos);
    c = max(c, cal);
    pos = x[i];
    if (x[i] < C / 2) {
      vcw[i] = cal;
      vcw0[i + 1] = cal - x[i];
    }
  }
  for (long long i = 0, cal = 0, pos = C; i < N; ++i) {
    cal += v[N - 1 - i] - (pos - x[N - 1 - i]);
    c = max(c, cal);
    pos = x[N - 1 - i];
    if (x[N - 1 - i] > C / 2) {
      vccw[i] = cal;
      vccw0[i + 1] = cal - (C - x[N - 1 - i]);
    }
  }
  c = max(c, (*max_element(vcw.begin(), vcw.end())) +
                 *(max_element(vccw0.begin(), vccw0.end())));
  c = max(c, (*max_element(vccw.begin(), vccw.end())) +
                 *(max_element(vcw0.begin(), vcw0.end())));
  cout << c << endl;
  return 0;
}
