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