#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int n, d;
  cin >> n >> d;
  pair<int, int> a[n];
  long long int b[n + 1], max1 = 0, c[n];
  b[0] = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a, a + n);
  for (int i = 0; i < n; ++i) {
    b[i + 1] = b[i] + a[i].second;
    c[i] = a[i].first;
  }
  for (int i = 0; i < n; ++i) {
    int index = lower_bound(c, c + n, c[i] + d) - c;
    max1 = max(max1, b[index] - b[i]);
  }
  cout << max1;
  return 0;
}
