#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long int money, friendship;
};
bool cmp(edge A, edge B) { return A.money < B.money; }
vector<edge> vv;
int main() {
  edge get;
  long long int i, j, n, m, d, s, sum = 0, maxx = 0;
  cin >> n >> d;
  for (i = 0; i < n; i++) {
    cin >> m >> s;
    get.money = m;
    get.friendship = s;
    vv.push_back(get);
  }
  sort(vv.begin(), vv.end(), cmp);
  i = 0, j = 0;
  if (n == 1)
    cout << vv[0].friendship << endl;
  else {
    for (i = 0; i < n;) {
      while (j < n && (vv[j].money - vv[i].money) < d) {
        sum += vv[j].friendship;
        j++;
      }
      maxx = max(maxx, sum);
      if (j >= n) break;
      sum = sum - vv[i].friendship;
      i++;
    }
    cout << maxx << endl;
  }
  return 0;
}
