#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, d, x, y, i = 0, j = 0;
  long long unsigned f = 0, maxx = 0;
  cin >> n >> d;
  vector<pair<int, int> > arr;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    arr.push_back(make_pair(x, y));
  }
  sort(arr.begin(), arr.end());
  for (i = 0; i < n; i++) {
    if (arr[i].first - arr[j].first >= d) {
      maxx = max(maxx, f);
      while (arr[i].first - arr[j].first >= d) {
        f -= arr[j].second;
        j++;
      }
    }
    f += arr[i].second;
  }
  maxx = max(maxx, f);
  cout << maxx;
}
