#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  vector<pair<int, int> > v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  long long int sum = v[0].second, sum1 = v[0].second;
  bool b = false;
  int start = 0;
  for (int i = 1; i < n; i++) {
    if (i == start) {
      sum1 += v[i].second;
      if (sum1 > sum) sum = sum1;
      continue;
    }
    if (v[i].first - v[start].first < d)
      sum1 += v[i].second;
    else {
      sum1 -= v[start].second;
      i--;
      start++;
    }
    if (sum1 > sum) sum = sum1;
  }
  cout << sum;
  return 0;
}
