#include <bits/stdc++.h>
struct help {
  long int money;
  long int friends;
};
void fusion_sort(struct help *p, long int n);
void bablesort(struct help *p, long int n);
int main() {
  long int n, m;
  scanf("%ld %ld", &n, &m);
  struct help *p = (struct help *)malloc(sizeof(struct help) * n);
  for (int i = 0; i < n; i++) scanf("%ld %ld", &p[i].money, &p[i].friends);
  if (n == 1) {
    printf("%ld", p[0].friends);
    return 0;
  }
  if (n > 1000)
    fusion_sort(p, n);
  else
    bablesort(p, n);
  unsigned long long max_friend = 0;
  unsigned long long cur_sum = 0;
  for (int b = 0, e = 0; e < n;)
    if (p[e].money - p[b].money >= m) {
      if (cur_sum > max_friend) {
        max_friend = cur_sum;
      }
      cur_sum -= p[b].friends;
      b++;
    } else {
      cur_sum += p[e].friends;
      e++;
    }
  if (cur_sum > max_friend) max_friend = cur_sum;
  printf("%lld", max_friend);
  return 0;
}
void fusion_sort(struct help *p, long int n) {
  if (n > 2) {
    fusion_sort(p, n / 2);
    fusion_sort((p + n / 2), n / 2 + n % 2);
  }
  struct help temp;
  for (int i = 0, j = n / 2; i < j && j < n; i++)
    if (p[i].money > p[j].money) {
      temp.friends = p[j].friends;
      temp.money = p[j].money;
      for (int k = j; k > i; k--) {
        p[k].friends = p[k - 1].friends;
        p[k].money = p[k - 1].money;
      }
      p[i].friends = temp.friends;
      p[i].money = temp.money;
      j++;
    }
}
void bablesort(struct help *p, long int n) {
  long int fr;
  long int mo;
  while (n > 1) {
    for (int i = 0; i < n - 1; i++)
      if (p[i].money > p[i + 1].money) {
        fr = p[i].friends;
        mo = p[i].money;
        p[i].friends = p[i + 1].friends;
        p[i].money = p[i + 1].money;
        p[i + 1].friends = fr;
        p[i + 1].money = mo;
      }
    n--;
  }
}
