#include <bits/stdc++.h>
using namespace std;
long long n, d, now = 0, ans = 0;
pair<long long, long long> a[100005];
void solve() {
  cin >> n >> d;
  for (long long i = (0); i < (n); ++i) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a, a + n);
  int right = n - 1;
  for (int left = n - 1; left >= 0; left--) {
    if (a[right].first - a[left].first < d) {
      now += a[left].second;
    } else {
      ans = max(now, ans);
      now += a[left].second;
      while (a[right].first - a[left].first >= d && right > left) {
        now -= a[right].second;
        right--;
      }
      ans = max(now, ans);
    }
  }
  ans = max(now, ans);
  cout << ans;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
