#include <bits/stdc++.h>
typedef struct Friend {
  long long m, s;
} F;
long long n, d, res = 0;
F a[100001];
void quicksort(long long d, long long c) {
  if (d >= c) return;
  srand(time(NULL));
  long long i1 = d, j1 = c, val = a[d + rand() % (c - d + 1)].m;
  while (i1 <= j1) {
    while (a[i1].m < val) i1++;
    while (a[j1].m > val) j1--;
    if (i1 <= j1) {
      if (i1 < j1) {
        F tmp = a[i1];
        a[i1] = a[j1];
        a[j1] = tmp;
      }
      i1++;
      j1--;
    }
  }
  quicksort(d, j1);
  quicksort(i1, c);
}
int main() {
  scanf("%I64d%I64d", &n, &d);
  for (long long i = 1; i <= n; i++) scanf("%I64d%I64d", &a[i].m, &a[i].s);
  quicksort(1, n);
  a[0].s = 0;
  for (long long i = 1; i <= n; i++) a[i].s += a[i - 1].s;
  long long j = 1;
  for (long long i = 1; i <= n; i++) {
    while (j < n && a[j + 1].m - a[i].m < d) j++;
    if (a[j].s - a[i - 1].s > res) res = a[j].s - a[i - 1].s;
  }
  printf("%I64d", res);
  return 0;
}
