#include <bits/stdc++.h>
template <class T>
struct greater {
  bool operator()(const T& x, const T& y) const { return x > y; }
};
using namespace std;
int n, d;
long long int res, ii, s;
vector<pair<long long int, long long int>> a;
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a.push_back(make_pair(x, y));
  }
  sort(a.begin(), a.end());
  s = 0, ii = 0;
  for (int i = 0; i < n; i++) {
    s += a[i].second;
    while (a[i].first - a[ii].first >= d) {
      s -= a[ii].second;
      ii++;
      if (ii == n) break;
    }
    res = max(res, s);
  }
  cout << res << endl;
  return 0;
}
