#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
struct ones {
  int a, b;
} f[N];
int cmp(const ones &a, const ones &b) { return a.a < b.a; }
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d%d", &f[i].a, &f[i].b);
  sort(f + 1, f + n + 1, cmp);
  int zz = 1;
  long long ans = 0, now = 0;
  for (int i = 1; i <= n; i++) {
    while (f[i].a - f[zz].a >= m) {
      now = now - (long long)f[zz].b;
      zz++;
    }
    now += (long long)f[i].b;
    if (now > ans) ans = now;
  }
  cout << ans << endl;
  return 0;
}
