#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d;
  cin >> n >> d;
  vector<pair<long long, long long>> v;
  long long a, b;
  for (long long i = 0; i < n; i++) {
    cin >> a >> b;
    v.push_back({a, b});
  }
  sort(v.begin(), v.end());
  long long i = 0, j = 0, ma = 0, cur = 0;
  while (j < v.size()) {
    if (v[j].first - v[i].first < d) {
      cur += v[j].second;
      ma = max(cur, ma);
      j++;
    } else {
      cur -= v[i].second;
      ma = max(cur, ma);
      i++;
      if (i > j) {
        j = i;
      }
    }
  }
  cout << ma;
  return 0;
}
