#include <bits/stdc++.h>
using namespace std;
struct prieten {
  int first, second;
};
prieten a[100002];
int d;
int main() {
  int n, i, j;
  long long lmax = 0;
  pair<int, int> a[100002];
  cin >> n >> d;
  for (i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
  sort(a + 1, a + n + 1);
  j = 1;
  long long sc = 0;
  for (i = 1; i <= n; i++) {
    sc += a[i].second;
    while (j <= i && a[i].first - a[j].first >= d) {
      sc -= a[j].second;
      j++;
    }
    lmax = max(lmax, sc);
  }
  cout << lmax;
  return 0;
}
