#include <bits/stdc++.h>
using namespace std;
long long n;
long long c;
vector<pair<long long, long long>> xv;
vector<long long> lef, rig;
long long leftgain(int num) {
  if (num == 0) return 0;
  return lef[num] - xv[num - 1].first;
}
long long riggain(int num) {
  if (num == 0) return 0;
  long long dis = c - xv[n - num].first;
  return rig[num] - dis;
}
int main() {
  cin >> n >> c;
  xv = vector<pair<long long, long long>>(n);
  for (int i = (0); i < (int)(n); i++) cin >> xv[i].first >> xv[i].second;
  sort(xv.begin(), xv.end());
  lef = vector<long long>(n + 1, 0);
  rig = vector<long long>(n + 1, 0);
  for (int i = (1); i < (int)(n + 1); i++) {
    lef[i] += lef[i - 1] + xv[i - 1].second;
    rig[i] += rig[i - 1] + xv[n - i].second;
  }
  long long ans = 0;
  for (int le = (0); le <= (int)(n); le++) {
    long long ltor = le >= 1 ? xv[le - 1].first : 0;
    long long lg = leftgain(le);
    for (int ri = (0); ri <= (int)(n - le); ri++) {
      long long rtol = ri >= 1 ? c - xv[n - ri].first : 0;
      long long rg = riggain(ri);
      long long cmn = lg + rg;
      ans = max({ans, cmn - ltor, cmn - rtol});
    }
  }
  cout << ans;
  return 0;
}
