#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, d;
  long long int m, f;
  long long int sum = 0;
  long long int max = 0;
  cin >> n >> d;
  vector<long long int> arr(n);
  map<long long int, long long int> mapp;
  vector<long long int> fac;
  for (int i = 0; i < n; ++i) {
    cin >> m >> f;
    arr[i] = m;
    mapp[m] += f;
  }
  sort(arr.begin(), arr.end());
  int i = 0;
  arr.erase(unique(arr.begin(), arr.end()), arr.end());
  for (auto it = mapp.begin(); it != mapp.end(); it++) {
    sum += it->second;
    fac.push_back(sum);
    ++i;
  }
  long long int sz = arr.size();
  for (int i = 0; i < sz; ++i) {
    long long int key = arr[i] + d - 1;
    auto upper = upper_bound(arr.begin(), arr.end(), key);
    long long int index = upper - arr.begin() - 1;
    if (fac[index] - fac[i - 1] > max && i != 0)
      max = fac[index] - fac[i - 1];
    else if (i == 0 && fac[index] > max)
      max = fac[index];
  }
  cout << max;
  return 0;
}
