#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
struct xx {
  bool operator()(pair<int, int>& x, pair<int, int>& y) {
    return y.first > x.first;
  }
};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int n, d;
  cin >> n >> d;
  vector<pair<int, int>> arr(n);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    arr[i] = {x, y};
  }
  sort(arr.begin(), arr.end(), xx());
  long long max_factor = INT_MIN;
  long long maxx = 0;
  int j = 0;
  for (int i = 0; i < n && j < n;) {
    if (abs(arr[j].first - arr[i].first) < d) {
      maxx += arr[j].second;
      j++;
    } else {
      {
        string _s = "maxx";
        replace(_s.begin(), _s.end(), ',', ' ');
        stringstream _ss(_s);
        istream_iterator<string> _it(_ss);
        err(_it, maxx);
      };
      max_factor = max(maxx, max_factor);
      maxx -= arr[i].second;
      i++;
    }
    max_factor = max(maxx, max_factor);
  }
  cout << max_factor;
}
