#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long seve[1000000] = {0};
void seive() {
  long long i, j;
  seve[0] = 1;
  seve[1] = 1;
  for (i = 2; i <= 1000000; i++) {
    if (seve[i] == 0) {
      for (j = i * i; j <= 1000000; j = j + i) seve[j] = 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n = 0, i, m, j, k = 0, ans = 0, z, x, y, b, d;
  string s, p;
  cin >> n >> d;
  vector<pair<long long, long long> > v;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back({x, y});
  }
  sort(v.begin(), v.end());
  long long sum = 0;
  j = 0;
  for (i = 0; i < n; i++) {
    while (j < n && v[j].first < v[i].first + d) {
      sum += v[j].second;
      j++;
    }
    ans = max(ans, sum);
    sum -= v[i].second;
  }
  cout << ans;
}
