#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  array<long long, 2> a[n];
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    a[i] = {x, y};
  }
  sort(a, a + n);
  long long arr[n][2];
  arr[0][0] = a[0][0];
  arr[0][1] = a[0][1];
  for (int i = 1; i < n; i++) {
    arr[i][0] = a[i][0];
    arr[i][1] = a[i][1];
  }
  for (int i = 1; i < n; i++) {
    arr[i][1] = arr[i][1] + arr[i - 1][1];
  }
  long long ans = 0;
  int l = 0;
  for (int i = 0; i < n; i++) {
    if ((arr[i][0] - arr[l][0]) >= d) {
      if (l == 0) {
        ans = max(ans, arr[i - 1][1]);
      } else {
        ans = max(ans, arr[i - 1][1] - arr[l - 1][1]);
      }
      while ((arr[i][0] - arr[l][0]) >= d) {
        l++;
      }
      ans = max(ans, arr[i][1] - arr[l - 1][1]);
    }
  }
  if (l == 0) {
    ans = max(ans, arr[n - 1][1]);
  } else {
    ans = max(ans, arr[n - 1][1] - arr[l - 1][1]);
  }
  cout << ans << endl;
}
