#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, j = 0;
  cin >> n >> k;
  pair<long long int, long long int> arr[n];
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
  }
  sort(arr, arr + n);
  long long int sum = 0, ans = 0;
  for (long long int i = 0; i < n; i++) {
    while (j < n && arr[j].first < arr[i].first + k) {
      sum = sum + arr[j].second;
      j++;
    }
    if (ans < sum) ans = sum;
    sum -= arr[i].second;
  }
  cout << ans;
  return 0;
}
