#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> j, pair<int, int> i) {
  if (j.first < i.first) return 1;
  return 0;
}
int main() {
  int n, d, cur = 0;
  long long mx = 0, cnt = 0;
  cin >> n >> d;
  pair<int, int> *a = new pair<int, int>[n];
  for (int i = 0; i < n; cin >> a[i].first >> a[i].second, i++)
    ;
  sort(a, a + n, cmp);
  cur = a[0].first;
  cnt = a[0].second;
  for (int i = 0, r = 1; i < n; i++) {
    cur = a[i].first;
    while ((r < n) && (a[r].first - cur < d)) {
      cnt += a[r].second;
      r++;
    }
    mx = max(mx, cnt);
    cnt -= a[i].second;
  }
  cout << mx << endl;
  return 0;
}
