#include <bits/stdc++.h>
using namespace std;
void Solve() {
  vector<pair<int, int>> vec;
  long long n, d, m, s, cr = 0, l = 0, r = 0, mx = 0;
  cin >> n >> d;
  for (long long i = 0; i < n; i++) {
    cin >> m >> s;
    vec.push_back(make_pair(m, s));
  }
  sort(vec.begin(), vec.end());
  for (long long l = 0; l < n && r < n; l++) {
    r = max(r, l);
    while (vec[r].first - vec[l].first < d && r < n) {
      cr += vec[r].second;
      mx = max(mx, cr);
      r++;
    }
    cr -= vec[l].second;
  }
  cout << mx;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    Solve();
  }
  return 0;
}
