#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
  uniform_int_distribution<int> uid(0, lim - 1);
  return uid(rang);
}
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
void solve() {
  long long n, d;
  cin >> n >> d;
  vector<pair<long long, long long> > v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  vector<long long> cs(n, 0);
  for (long long i = 0; i < n; i++) {
    cs[i] = v[i].second;
    if (i) cs[i] += cs[i - 1];
  }
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    pair<long long, long long> p = {v[i].first + d, -1};
    long long idx = lower_bound(v.begin(), v.end(), p) - v.begin() - 1;
    long long curr_res = cs[idx];
    if (i) curr_res -= cs[i - 1];
    res = max(res, curr_res);
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
