#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, long long> > ss;
  for (int i = 0; i < n; i++) {
    long long x, v;
    cin >> x >> v;
    ss.push_back(make_pair(x, v));
  }
  sort(ss.begin(), ss.end());
  long long mmru[100000], mmri[100000];
  for (int i = 0; i < 100000; i++) mmru[i] = mmri[i] = 0;
  long long tv = 0;
  long long mxri = 0, mxru = 0;
  for (int i = 0; i < ss.size(); i++) {
    tv += ss[i].second;
    long long x = ss[i].first;
    mxri = max(mxri, tv - x);
    mxru = max(mxru, tv - x * 2);
    mmru[i] = mxru;
    mmri[i] = mxri;
  }
  long long mx = 0;
  tv = 0;
  long long mxli = 0, mxlu = 0;
  for (int i = ss.size() - 1; i >= 0; i--) {
    tv += ss[i].second;
    long long x = c - ss[i].first;
    mxli = max(mxli, tv - x);
    mxlu = max(mxlu, tv - x * 2);
    long long ru;
    if (i >= 1)
      ru = mmru[i - 1];
    else
      ru = 0;
    mx = max(mx, mxli + ru);
    long long ri;
    if (i >= 1)
      ri = mmri[i - 1];
    else
      ri = 0;
    mx = max(mx, mxlu + ri);
  }
  cout << mx << endl;
  return 0;
}
