#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
pair<int, int> a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
  sort(a, a + n);
  int L = 0, R = 0;
  long long temp = 0, ans = INT_MIN;
  while (R < n) {
    temp += a[R++].second;
    while (a[R - 1].first - a[L].first >= d) temp -= a[L++].second;
    ans = max(ans, temp);
  }
  cout << ans << '\n';
  return 0;
}
