#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, t, i, sum = 0, l, r, m = 0;
  cin >> n >> t;
  pair<long long int, long long int> a[n];
  l = 0;
  r = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a, a + n);
  while (l < n) {
    if (a[l].first - a[r].first < t) {
      sum += a[l].second;
      l++;
      m = max(m, sum);
    } else
      sum -= a[r++].second;
  }
  cout << m << endl;
  return 0;
}
