#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int32_t main() {
  unsigned long long n = 0;
  unsigned long long d = 0;
  cin >> n >> d;
  vector<pair<unsigned long long, unsigned long long>> a(n);
  for (unsigned long long i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  unsigned long long ans = 0;
  unsigned long long max = 0;
  for (long long l = 0, r = 0; l < n && r < n; max -= a[l].second, l++) {
    while (r < n && a[r].first - a[l].first < d) {
      max += a[r].second;
      r++;
    }
    if (max > ans) ans = max;
  }
  cout << ans;
}
