#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long d;
  cin >> n >> d;
  vector<vector<long long> > fr;
  fr.resize(n, vector<long long>(2, 0));
  for (int i = 0; i < n; i++) {
    cin >> fr[i][0];
    cin >> fr[i][1];
  }
  sort(fr.begin(), fr.end());
  for (int i = 1; i < n; i++) {
    fr[i][1] += fr[i - 1][1];
  }
  long long bestSofar = 0;
  int left = 0;
  int right = 0;
  while (right < n) {
    while (fr[right][0] - fr[left][0] >= d) left++;
    long long myBoy;
    if (left == right) {
      if (left == 0)
        myBoy = fr[left][1];
      else
        myBoy = fr[left][1] - fr[left - 1][1];
      if (bestSofar < myBoy) bestSofar = myBoy;
    } else {
      if (left != 0)
        myBoy = fr[right][1] - fr[left - 1][1];
      else
        myBoy = fr[right][1];
      if (bestSofar < myBoy) bestSofar = myBoy;
    }
    right++;
  }
  printf("%I64d\n", bestSofar);
  return 0;
}
