#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
long long d, dp[N];
pair<long long, long long> arr[N];
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first < b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    arr[i] = {a, b};
  }
  sort(arr + 1, arr + 1 + n, cmp);
  dp[1] = arr[1].second;
  for (int i = 2; i <= n; i++) {
    dp[i] = dp[i - 1] + arr[i].second;
  }
  long long answer = -1;
  for (int i = 1; i <= n; i++) {
    long long target = arr[i].first + d - 1;
    int l = 1;
    int r = n;
    int ans = -1;
    while (l <= r) {
      int mid = l + (r - l) / 2;
      if (arr[mid].first <= target) {
        ans = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    answer = max(answer, dp[ans] - dp[i - 1]);
  }
  cout << answer << '\n';
  return 0;
}
