#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  long long n;
  long long d;
  cin >> n >> d;
  vector<pair<long long, long long>> friends;
  long long money;
  long long factor;
  for (long long i = 0; i < n; i++) {
    cin >> money >> factor;
    friends.push_back(make_pair(money, factor));
  }
  sort(friends.rbegin(), friends.rend());
  long long total_factor = friends[0].second;
  long long temp_factor = friends[0].second;
  long long firstPointer = 0;
  long long secondPointer = 1;
  while (secondPointer < friends.size()) {
    if (friends[firstPointer].first - friends[secondPointer].first < d) {
      temp_factor = temp_factor + friends[secondPointer].second;
      secondPointer = secondPointer + 1;
      ;
    } else {
      temp_factor = temp_factor - friends[firstPointer].second;
      firstPointer = firstPointer + 1;
    }
    total_factor = max(total_factor, temp_factor);
  }
  cout << total_factor << '\n';
  return 0;
}
