#include <bits/stdc++.h>
using namespace std;
struct Friend {
  int m, s;
};
Friend f[100005];
bool operator<(const Friend &a, const Friend &b) { return a.m < b.m; }
int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < n; ++i) cin >> f[i].m >> f[i].s;
  sort(f, f + n);
  long long Max = 0;
  long long sum = 0;
  int qian = 0;
  for (int i = 0; i < n; ++i) {
    if (f[i].m - f[qian].m >= d) {
      --i;
      sum -= f[qian].s;
      ++qian;
    } else {
      sum += f[i].s;
      if (sum > Max) Max = sum;
    }
  }
  cout << Max;
  return 0;
}
