#include <bits/stdc++.h>
using namespace std;
int n;
long long c;
vector<pair<long long, int> > info;
void hawawa() {
  cin >> n >> c;
  info.resize(n);
  for (int j = 0; j < n; j++) {
    auto&& i = info[j];
    cin >> i.first >> i.second;
    info.push_back(make_pair(-c + i.first, i.second));
  }
  sort(begin(info), end(info));
  long long ans = 0;
  for (int i = 0; i < 2 * n; i++) {
    long long cal = 0;
    for (int j = 0; j < n && i + j < 2 * n; j++) {
      cal += info[i + j].second;
      long long a = max(abs(info[i + j].first), abs(info[i].first));
      if (info[i + j].first > 0 && info[i].first < 0) {
        a = info[i + j].first - info[i].first +
            min(abs(info[i + j].first), abs(info[i].first));
      }
      ans = max(cal - a, ans);
    }
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  hawawa();
  return 0;
}
