#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> vt[100001];
int main() {
  int n, d;
  long long maxy = 0;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    long long a, b;
    scanf("%I64d%I64d", &a, &b);
    vt[i] = make_pair(a, b);
  }
  sort(vt, vt + n);
  for (int i = 0; i < n; i++) {
    if (i > 0) vt[i].second += vt[i - 1].second;
  }
  for (int i = 0; i < n; i++) {
    long long sum = 0;
    int l = i, r = n - 1, ans;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if ((vt[mid].first - vt[i].first) >= d) {
        r = mid - 1;
      } else {
        ans = mid;
        l = mid + 1;
      }
    }
    if (i > 0)
      sum = vt[ans].second - vt[i - 1].second;
    else
      sum = vt[ans].second;
    maxy = max(maxy, sum);
  }
  cout << maxy << endl;
}
