#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, diff;
  cin >> n >> diff;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[i] = make_pair(x, y);
  }
  sort(v.begin(), v.end());
  long long l = 0, r = 1, sum = v[0].second, ans = sum;
  while (r < n) {
    if (abs(v[r].first - v[l].first) < diff) {
      sum += v[r].second;
      ans = max(sum, ans);
      r++;
    } else {
      sum -= v[l].second;
      l++;
    }
  }
  cout << ans << endl;
  return 0;
}
