#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > A;
long long n, d, a, b, ps = 1, ans;
long long pre[100001];
int main() {
  cin >> n >> d;
  A.push_back({0, 0});
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    A.push_back({a, b});
  }
  sort(A.begin(), A.end());
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + A[i].second;
    if (A[i].first - A[ps].first >= d) {
      while (1) {
        ps++;
        if (A[i].first - A[ps].first < d) break;
      }
    }
    ans = max(ans, pre[i] - pre[ps - 1]);
  }
  cout << ans << endl;
}
