#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<int>::iterator it;
vector<pair<int, int> > tmp;
int main() {
  int n, k, x, y, id, j;
  long long mx = -1, c[100002];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    tmp.push_back(make_pair(x, y));
  }
  sort(tmp.begin(), tmp.end());
  for (int i = 0; i < n; i++) {
    v.push_back(tmp[i].first);
    c[i + 1] = tmp[i].second;
  }
  for (int i = 1; i <= n; i++) c[i] = c[i] + c[i - 1];
  j = 0;
  for (int i = 0; i < n; i++) {
    while ((j < n) && v[i] + k > v[j]) {
      j++;
    }
    mx = max(mx, c[j] - c[i]);
  }
  cout << mx;
  return 0;
}
