#include <bits/stdc++.h>
using namespace std;
bool cmp(int n, pair<int, int> const& p) {
  return ((p.first < n) && (p.second < n));
}
int main() {
  int n, d;
  cin >> n >> d;
  pair<long long, long long> a[n + 1];
  long long b[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    b[i] = a[i].first;
    cin >> a[i].second;
  }
  sort(b, b + n);
  sort(a, a + n);
  long long c[n + 2];
  c[0] = 0;
  for (int i = 1; i <= n; i++) {
    c[i] = c[i - 1] + a[i - 1].second;
  }
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    long long sum = 0;
    long long j = upper_bound(b, b + n, a[i].first + d - 1) - b;
    sum = c[j] - c[i];
    mx = max(mx, sum);
  }
  cout << mx << '\n';
}
