#include <bits/stdc++.h>
using namespace std;
int n, d;
vector<pair<int, int> > v;
int BS(int x) {
  int l = x + 1, r = n - 1, mid, res = -1;
  while (r >= l) {
    mid = (l + r) / 2;
    if (v[mid].first - v[x].first < d) {
      res = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &d);
  v.resize(n);
  vector<long long> sum;
  sum.resize(n + 1);
  sum[0] = 0;
  for (int i = 0; i < n; i++) {
    int m, f;
    scanf("%d%d", &m, &f);
    v[i] = make_pair(m, f);
  }
  sort(v.begin(), v.end());
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + v[i - 1].second;
  long long mx = 0;
  for (int i = 0; i < n; i++) {
    long long res;
    int x = BS(i);
    if (x != -1)
      res = sum[x + 1] - sum[i];
    else
      res = sum[i + 1] - sum[i];
    mx = max(res, mx);
  }
  printf("%I64d\n", mx);
  return 0;
}
