#include <bits/stdc++.h>
typedef std::pair<int, int> PII;
int main() {
  int n;
  int d;
  long long ans = 0;
  long long sum = 0;
  std::vector<PII> v;
  std::cin >> n >> d;
  v.resize(n);
  for (int i = 0; i < n; ++i) std::cin >> v[i].first >> v[i].second;
  std::sort(v.begin(), v.end());
  int j = 0;
  for (int i = 0; i < n; ++i) {
    while (j < n && v[j].first - v[i].first < d) {
      sum += v[j].second;
      ++j;
    }
    ans = std::max(ans, sum);
    sum -= v[i].second;
  }
  std::cout << ans << std::endl;
  return 0;
}
