#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::cout.precision(15);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> v;
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  sort(v.begin(), v.end());
  long long o = 0, ma = 0, l, r = 0;
  for (l = 0; l < n; l++) {
    while (r < n && abs(v[l].first - v[r].first) < m) {
      o = o + v[r].second;
      r++;
    }
    if (o >= ma) ma = o;
    o = o - v[l].second;
  }
  cout << ma;
}
