#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 3990;
struct A {
  int m, s;
  A(int m, int s) : m(m), s(s) {}
  A() : m(0), s(0) {}
  bool operator<(const A &C) const {
    if (m != C.m)
      return m < C.m;
    else
      return s < C.s;
  }
} a[maxn];
int n, d;
long long sum[maxn];
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    int m, s;
    scanf("%d%d", &m, &s);
    a[i].m = m, a[i].s = s;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + a[i].s;
  }
  long long maxsum = 0;
  for (int i = 1; i <= n; i++) {
    A *p = lower_bound(a + 1, a + n + 1, A(a[i].m - 1 + d, 1e9));
    if (p->m >= a[i].m + d || p - a > n) p--;
    int pos = p - a;
    maxsum = max(maxsum, sum[pos] - sum[i - 1]);
  }
  cout << maxsum << endl;
  return 0;
}
