#include <bits/stdc++.h>
using namespace std;
int n, d;
vector<pair<int, int> > friends;
long long int sum_p[100001];
bool compare(pair<int, int> P1, pair<int, int> P2) {
  if (P1.first < P2.first) return true;
  return false;
}
int BinarySearch(int start, int key) {
  int step, i = start;
  for (step = 1; step <= (n - start + 1); step <<= 1)
    ;
  for (; step; step >>= 1)
    if (i + step <= n && friends[i + step].first <= key) i = i + step;
  return i;
}
int main() {
  cin >> n >> d;
  int x, y;
  friends.push_back(make_pair(0, 0));
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    friends.push_back(make_pair(x, y));
  }
  sort(friends.begin() + 1, friends.end(), compare);
  sum_p[1] = friends[1].second;
  for (int i = 2; i <= n; i++)
    sum_p[i] = sum_p[i - 1] + (long long)friends[i].second;
  int right_pos;
  long long int best = 0;
  for (int i = 1; i <= n; i++) {
    right_pos = BinarySearch(i, friends[i].first + d - 1);
    best = max(best, sum_p[right_pos] - sum_p[i - 1]);
  }
  cout << best << "\n";
  return 0;
}
