#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int MAX = 1e5;
void sujho() {
  long long int n, diff;
  cin >> n >> diff;
  vector<pair<long long int, long long int>> v;
  long long int mx = 0;
  for (long long int i = 0; i < (n); i++) {
    long long int x, y;
    cin >> x >> y;
    if (y > mx) mx = y;
    v.push_back({x, y});
  }
  sort(v.begin(), v.end());
  vector<long long int> suf(n, 0);
  for (long long int i = 0; i < (n); i++) {
    suf[i + 1] = v[i].second + suf[i];
  }
  long long int i = 0;
  long long int j = 0;
  while (i < n && j < n) {
    if (i == j) {
      mx = max(mx, suf[j + 1] - suf[j]);
      j++;
    } else if (v[j].first - v[i].first < diff) {
      mx = max(mx, suf[j + 1] - suf[i]);
      j++;
    } else {
      i++;
    }
  }
  cout << mx << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  { sujho(); }
  return 0;
}
