#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, int> > v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  long long curv = 0;
  vector<long long> maxlo(n), maxlr(n);
  long long maxloi = 0, maxlri = 0;
  for (int i = 0; i < n; i++) {
    curv += v[i].second;
    maxloi = max(maxloi, curv - v[i].first);
    maxlri = max(maxlri, curv - 2 * v[i].first);
    maxlo[i] = maxloi;
    maxlr[i] = maxlri;
  }
  curv = 0;
  long long maxroi = 0, maxrri = 0, res = 0;
  res = maxlo[n];
  for (int i = n - 1; 0 <= i; i--) {
    curv += v[i].second;
    maxroi = max(maxroi, curv - (c - v[i].first));
    maxrri = max(maxrri, curv - 2 * (c - v[i].first));
    if (i != 0)
      res = max({res, maxroi, maxroi + maxlr[i - 1], maxrri + maxlo[i - 1]});
  }
  res = max({res, maxroi, 0ll});
  cout << res << endl;
  return 0;
}
