#include <bits/stdc++.h>
using namespace std;
long long n, d, a, b, cek, sum, ans;
vector<pair<long long, long long> > v;
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    v.push_back({a, b});
  }
  sort(v.begin(), v.end());
  long long id = 0;
  for (int i = 0; i < n; i++) {
    cek = v[i].first - v[id].first;
    sum += v[i].second;
    while (cek >= d) {
      sum -= v[id].second;
      id++;
      cek = v[i].first - v[id].first;
    }
    ans = max(ans, sum);
  }
  cout << ans << "\n";
}
