#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned int n, d;
  while (cin >> n >> d) {
    vector<pair<unsigned long long, unsigned long long>> ms(n);
    for (size_t i = 0; i < n; ++i) cin >> ms[i].first >> ms[i].second;
    sort(ms.begin(), ms.end());
    unsigned long long factor = ms[0].second;
    size_t left = 0, right = 1;
    unsigned long long result = factor;
    while (right < n) {
      while (right < n && ms[right].first - ms[left].first < d)
        factor += ms[right].second, ++right;
      result = max(result, factor);
      factor -= ms[left].second;
      ++left;
    }
    cout << result << endl;
  }
}
