#include <bits/stdc++.h>
using namespace std;
struct ff {
  long long int x, y;
} pok[100001];
bool comp(ff a, ff b) { return a.x < b.x; }
int main() {
  long long int i, n, m, temp, ans, k = 0;
  scanf("%I64d %I64d", &n, &m);
  for (i = 0; i < n; i++) scanf("%I64d %I64d", &pok[i].x, &pok[i].y);
  sort(pok, pok + n, comp);
  ans = pok[k].y;
  temp = ans;
  for (i = 1; i < n; i++) {
    if (pok[i].x - pok[k].x < m) {
      ans += pok[i].y;
      if (ans >= temp) temp = ans;
    } else {
      if (ans >= temp) temp = ans;
      ans = ans - pok[k].y;
      k++;
      i--;
    }
  }
  printf("%I64d\n", temp);
  return 0;
}
