#include <bits/stdc++.h>
using namespace std;
long long n, d, start, sum, mx;
pair<long long, long long> a[100100];
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a, a + n);
  sum = mx = a[0].second;
  for (int i = 1; i < n; i++) {
    if (a[i].first - a[start].first < d) {
      sum += a[i].second;
      mx = max(mx, sum);
    } else {
      while (a[i].first - a[start].first >= d) {
        sum -= a[start].second;
        start++;
      }
      sum += a[i].second;
      mx = max(mx, sum);
    }
  }
  cout << mx << endl;
  return 0;
}
