#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  pair<int, int> friendlist[100001];
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++)
    scanf("%d%d", &((friendlist + i)->first), &((friendlist + i)->second));
  sort(friendlist, friendlist + n);
  int it_left = 0;
  int it_right = 0;
  long long maxfriendship = 0;
  long long friendship = 0;
  while (true) {
    while (it_right < n &&
           friendlist[it_right].first - friendlist[it_left].first < d) {
      friendship += friendlist[it_right].second;
      maxfriendship = max(maxfriendship, friendship);
      it_right++;
    }
    if (it_right >= n) break;
    while (friendlist[it_right].first - friendlist[it_left].first >= d) {
      friendship -= friendlist[it_left].second;
      it_left++;
    }
  }
  cout << maxfriendship;
  return 0;
}
