#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<pair<int, int> > A;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    A.push_back(make_pair(x, y));
  }
  sort(A.begin(), A.end());
  long long ans = 0;
  long long co = 0;
  long long pre;
  vector<pair<int, int> >::iterator it = A.begin();
  vector<pair<int, int> >::iterator fir = A.begin();
  co = (*it).second;
  pre = (*it).first;
  ans = (*it).second;
  it++;
  for (; it != A.end(); it++) {
    while ((*it).first - ((*fir).first) >= k) {
      co = co - (*fir).second;
      fir++;
    }
    co += (*it).second;
    ans = max(ans, co);
  }
  printf("%lld", ans);
  return 0;
}
