#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, C;
  cin >> N >> C;
  vector<pair<long long, long long>> xv;
  for (int i = 0; i < N; i++) {
    long long x, v;
    cin >> x >> v;
    xv.emplace_back(x, v);
    xv.emplace_back(x - C, v);
  }
  sort((xv).begin(), (xv).end());
  int center = xv.size() / 2;
  for (int i = center + 1; i < xv.size(); i++) {
    xv[i].second += xv[i - 1].second;
  }
  for (int i = center - 2; i >= 0; i--) {
    xv[i].second += xv[i + 1].second;
  }
  long long score = 0;
  for (int i = N; i < xv.size(); i++)
    score = max(score, xv[i].second - xv[i].first);
  for (int i = N - 1; i >= 0; i--)
    score = max(score, xv[i].second + xv[i].first);
  for (int i = N; i < xv.size(); i++) {
    for (int j = N - 1; abs(j - i) < N; j--) {
      score = max(score, xv[i].second + xv[j].second -
                             abs(2 * xv[i].first - xv[j].first));
    }
  }
  for (int i = N - 1; i >= 0; i--) {
    for (int j = N; abs(j - i) < N; j++) {
      score = max(score, xv[i].second + xv[j].second -
                             abs(-2 * xv[i].first + xv[j].first));
    }
  }
  cout << score << endl;
  return 0;
}
