#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct node {
  int mon, fac;
  bool operator<(const node& t) const { return mon < t.mon; }
} st[maxn];
long long sum[maxn] = {0};
int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) cin >> st[i].mon >> st[i].fac;
  sort(st + 1, st + n + 1);
  for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + st[i].fac;
  int l = 1, r = 1;
  long long ans = 0;
  for (; l <= n; ++l) {
    while (r <= n && st[r].mon - st[l].mon < d) r++;
    ans = max(ans, sum[r - 1] - sum[l - 1]);
  }
  printf("%lld\n", ans);
  return 0;
}
