#include <bits/stdc++.h>
using namespace std;
struct kefa {
  int amount;
  long factor;
  bool operator<(const kefa &kefas) const {
    if (amount < kefas.amount) return true;
    if (amount > kefas.amount) return false;
    if (factor < kefas.factor) return true;
    return false;
  }
};
kefa ar[100000];
long long cum_sum[100001], d;
int n;
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> ar[i].amount >> ar[i].factor;
  }
  sort(ar, ar + n);
  cum_sum[0] = 0;
  for (int i = 0; i < n; i++) {
    cum_sum[i + 1] = cum_sum[i] + ar[i].factor;
  }
  long long y = 0;
  for (int i = 0; i < n; i++) {
    kefa arfriend;
    arfriend.amount = ar[i].amount + d;
    arfriend.factor = 0;
    kefa *p = lower_bound(ar + i, ar + n, arfriend) - 1;
    int j = p - (ar + i);
    long long x = cum_sum[i + j + 1] - cum_sum[i];
    y = max(y, x);
    cerr << i << " " << j << " " << x << "\n";
  }
  cout << y;
  return 0;
}
