#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > x;
int main() {
  int n, d;
  cin >> n >> d;
  x = vector<pair<int, int> >(n);
  for (int i = 0; i < n; i++) cin >> x[i].first >> x[i].second;
  sort(x.begin(), x.end());
  long long maxx = 0;
  int lo = 0;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (x[i].first - x[lo].first < d) {
      sum += x[i].second;
      maxx = max(sum, maxx);
    } else {
      sum -= x[lo].second;
      lo++;
      i--;
    }
  }
  cout << maxx;
  return 0;
}
