#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  v.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &v[i].first, &v[i].second);
  }
  sort(v.begin(), v.end());
  long long sum = 0, ans = 0;
  int l = 0, r = 0;
  while (r < n) {
    if (v[r].first - d < v[l].first) {
      sum += v[r].second;
      r++;
    } else {
      ans = max(ans, sum);
      sum -= v[l].second;
      l++;
    }
  }
  cout << max(ans, sum);
  return 0;
}
