#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d;
  cin >> n >> d;
  vector<pair<int, long long>> fr(n + 1);
  for (int i = 1; i <= n; i++) cin >> fr[i].first >> fr[i].second;
  sort(fr.begin(), fr.end());
  int j = 1;
  long long answ = -1;
  for (int i = 1; i <= n; i++) {
    fr[i].second += fr[i - 1].second;
    while (fr[i].first - fr[j].first >= d) j++;
    answ = max(answ, fr[i].second - fr[j - 1].second);
  }
  cout << answ;
  return 0;
}
