#include <bits/stdc++.h>
const int SIZE = 1e5 + 5;
using namespace std;
int n, d;
vector<pair<int, int> > arr;
int BS(int x) {
  int res = -1;
  int f = 0, e = n - 1;
  while (f <= e) {
    int m = (f + e) / 2;
    if (arr[m].first > x)
      e = m - 1, res = m;
    else
      f = m + 1, res = m + 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  cin >> n >> d;
  arr.resize(n);
  for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;
  sort(arr.begin(), arr.end());
  vector<long long> sum(n + 1);
  sum[0] = 0;
  for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + arr[i].second;
  long long res = 0;
  for (int i = 0; i < n; i++) {
    int idx = BS(arr[i].first + d - 1);
    res = max(res, sum[idx] - sum[i]);
  }
  cout << res;
}
