#include <bits/stdc++.h>
using namespace std;
int xDir[8] = {0, 0, -1, 1, 1, -1, -1, 1};
int yDir[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int EPS = 1e-10;
int dComp(double d1, double d2) {
  if (abs(d1 - d2) <= EPS) return 0;
  if (d1 > d2)
    return 1;
  else
    return -1;
}
bool lucky(int i) {
  string s = to_string(i);
  for (int j = 0; j < s.size(); j++)
    if (s[j] - '0' != 4 && s[j] - '0' != 7) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, d;
  cin >> n >> d;
  vector<pair<int, int> > vec(100001);
  for (int i = 0; i < n; i++) {
    cin >> vec[i].first >> vec[i].second;
  }
  sort(vec.begin(), vec.begin() + n);
  int left = 0, right = 0;
  long long sum = 0;
  long long mx = -1;
  while (left <= right && right < n && left < n) {
    if (abs(vec[left].first - vec[right].first) < d) {
      sum += vec[right].second;
      right++;
      mx = max(mx, sum);
    } else {
      sum -= vec[left].second;
      left++;
    }
    mx = max(mx, sum);
  }
  cout << mx << endl;
}
