#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n, d;
  long long sum[maxn];
  pair<int, int> a[maxn];
  while (cin >> n >> d) {
    for (int i = 1; i <= n; ++i) {
      cin >> a[i].first >> a[i].second;
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; ++i) {
      sum[i] = sum[i - 1] + a[i].second;
    }
    int j = 1;
    long long res = 0;
    for (int i = 0; i <= n; ++i) {
      while (a[i].first - a[j].first >= d) {
        ++j;
      }
      res = max(res, sum[i] - sum[j - 1]);
    }
    cout << res << endl;
  }
  return 0;
}
