#include <bits/stdc++.h>
using namespace std;
long long n, d, s = 0, kq = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  pair<long long, long long> a[100005];
  cin >> n >> d;
  for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  sort(a, a + n);
  for (int j = 0, i = 0; j < n; j++) {
    s += a[j].second;
    while (a[j].first - a[i].first >= d) s -= a[i++].second;
    kq = max(kq, s);
  }
  cout << kq;
}
