#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int i, d, j, k, l, t, n;
  cin >> n >> d;
  vector<pair<long long int, long long int>> v;
  l = -1;
  for (i = 0; i < n; i++) {
    cin >> j >> k;
    v.push_back(make_pair(j, k));
  }
  sort(v.begin(), v.end());
  long long int cnt = v[0].first;
  long long int ci = 0;
  long long int ans = v[0].second;
  long long int sum = v[0].second;
  for (i = 1; i < n; i++) {
    if (v[i].first - cnt < d) {
      sum += v[i].second;
      continue;
    } else {
      ans = max(ans, sum);
      sum += v[i].second;
      for (j = ci; j < i; j++) {
        if (v[i].first - v[j].first < d) {
          cnt = v[j].first;
          ci = j;
          break;
        } else
          sum -= v[j].second;
      }
      if (j == i) {
        cnt = v[i].first;
        ci = i;
      }
    }
  }
  ans = max(ans, sum);
  cout << ans << endl;
}
