#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long x, y, n, d, i, beg, p1 = 0;
  cin >> n >> d;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  long long minn = v[0].first, cur = v[0].second, ans = v[0].second;
  for (i = 1; i < n; i++) {
    if (v[i].first - minn >= d) {
      cur += v[i].second;
      while (p1 < i and v[i].first - v[p1].first >= d) {
        cur -= v[p1].second;
        p1++;
      }
      ans = max(ans, cur);
      minn = v[p1].first;
    } else {
      cur += v[i].second;
      ans = max(ans, cur);
    }
  }
  cout << ans << endl;
  return 0;
}
