#include <bits/stdc++.h>
using namespace std;
int d;
int n;
struct Pon {
  long long x, y;
} a[100100];
bool cmp(Pon A, Pon B) {
  if (A.x == B.x) return A.y < B.y;
  return A.x < B.x;
}
int main() {
  while (scanf("%d%d", &n, &d) != EOF) {
    long long mmax = 0;
    long long tot = 0;
    int pis = 0;
    for (int i = 0; i < n; i++) {
      scanf("%I64d%I64d", &a[i].x, &a[i].y);
    }
    sort(a, a + n, cmp);
    long long pos = a[0].x;
    for (int i = 0; i < n; i++) {
      if (a[i].x == pos) {
        tot += a[i].y;
      } else {
        pos = a[i].x;
        mmax = max(tot, mmax);
        tot = a[i].y;
      }
    }
    mmax = max(tot, mmax);
    int first = a[0].x;
    int i = 0, j = 0;
    long long ans = 0;
    while (i < n && j < n) {
      while (a[i].x - first < d && a[i].x - first >= 0 && i < n) {
        ans += a[i].y;
        i++;
      }
      mmax = max(ans, mmax);
      while (a[i].x - a[j].x >= d && j < n) {
        ans -= a[j].y;
        j++;
      }
      first = a[j].x;
    }
    printf("%I64d\n", mmax);
  }
  return 0;
}
