#include <bits/stdc++.h>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
struct prieten {
  int money;
  int friendship;
} v[100001];
int part_Hoare(int s, int d) {
  int i, j;
  i = s - 1;
  j = d + 1;
  int randpoz, r1, r2, r3;
  int nr = d - s + 1;
  r1 = rand() % nr + s;
  r2 = rand() % nr + s;
  r3 = rand() % nr + s;
  int minr, maxr;
  minr = min(min(r1, r2), min(r2, r3));
  maxr = max(max(r1, r2), max(r2, r3));
  randpoz = r1 + r2 + r3 - minr - maxr;
  int pivot = v[randpoz].money;
  while (true) {
    do {
      ++i;
    } while (v[i].money < pivot);
    do {
      --j;
    } while (v[j].money > pivot);
    if (i >= j) return j;
    prieten aux;
    aux.money = v[i].money;
    aux.friendship = v[i].friendship;
    v[i].money = v[j].money;
    v[i].friendship = v[j].friendship;
    v[j].money = aux.money;
    v[j].friendship = aux.friendship;
  }
}
void qsort(int i, int j) {
  if (i < j) {
    int k = part_Hoare(i, j);
    qsort(i, k);
    qsort(k + 1, j);
  }
}
int caut_bin(int st, int dr, int x, int dif) {
  int m = (st + dr) / 2;
  if (st >= dr) {
    if ((v[m].money - x) <= dif)
      return st;
    else
      return st - 1;
  }
  if ((v[m].money - x) > dif)
    return caut_bin(st, m - 1, x, dif);
  else
    return caut_bin(m + 1, dr, x, dif);
}
int main() {
  int n, d, i, j, k;
  long long smax = 0;
  cin >> n >> d;
  for (i = 1; i <= n; i++) cin >> v[i].money >> v[i].friendship;
  qsort(1, n);
  if ((v[2].money - v[1].money) < d) {
    j = caut_bin(2, n, v[i].money, d - 1);
    for (i = 1; i <= j; i++) smax += v[i].friendship;
  } else if (v[1].friendship > smax) {
    smax = v[1].friendship;
    j = 1;
  }
  i = 1;
  j++;
  long long spart = smax;
  while (j < n) {
    while (((v[j].money - v[i].money) >= d) && (i < j)) {
      spart -= v[i].friendship;
      i++;
    }
    while (((v[j].money - v[i].money) < d) && (j <= n)) {
      spart += v[j].friendship;
      j++;
    }
    if (spart > smax) smax = spart;
  }
  if (v[n].friendship > smax) smax = v[n].friendship;
  cout << smax;
  return 0;
}
