#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  long long n, d;
  cin >> n >> d;
  long long x[100000][2];
  for (int i = 0; i < n; i++) {
    cin >> x[i][0] >> x[i][1];
  }
  qsort(x, n, sizeof(*x), [](const void *arg1, const void *arg2) -> int {
    int const *lhs = static_cast<int const *>(arg1);
    int const *rhs = static_cast<int const *>(arg2);
    return (lhs[0] < rhs[0])
               ? -1
               : ((rhs[0] < lhs[0])
                      ? 1
                      : (lhs[1] < rhs[1] ? -1 : ((rhs[1] < lhs[1] ? 1 : 0))));
  });
  int j = 1;
  long long f = x[0][1], ans = 0;
  for (int i = 0; i < n; i++) {
    while (j < n && x[j][0] - x[i][0] < d) {
      f += x[j][1];
      j++;
    }
    if (ans < f) ans = f;
    f -= x[i][1];
  }
  cout << ans;
  return 0;
}
