#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, d;
  cin >> n >> d;
  vector<std::pair<int, int> > v;
  long long m, s;
  for (int i = 0; i < (n); ++i) {
    cin >> m >> s;
    v.push_back(make_pair(m, s));
  }
  sort(v.begin(), v.end());
  long long maxm = v[0].second, sum = 0, prev = v[0].first, index = 0;
  for (int i = 1; i <= (n - 1); ++i) {
    if (i == 1 && v[i].first - prev < d) {
      sum += v[i - 1].second;
      maxm = max(sum, maxm);
    }
    if (v[i].first - prev < d) {
      sum += v[i].second;
      maxm = max(sum, maxm);
    } else {
      sum -= v[index].second;
      maxm = max(sum, maxm);
      index++;
      prev = v[index].first;
      i--;
    }
  }
  cout << maxm;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
