#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 1;
long long ans = -1e18, n, d, pre[N], tmp = 0;
vector<pair<long long, long long>> v;
int main() {
  cin >> n >> d;
  long long x, y;
  v.push_back({-1, -1});
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    v.push_back({x, y});
  }
  sort(v.begin(), v.end());
  pre[0] = 0;
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + v[i].second;
  long long i, j = 1;
  for (i = 1; i <= n; i++) {
    while (v[i].first - v[j].first >= d) {
      j++;
    }
    tmp = pre[i] - pre[j - 1];
    ans = max(ans, tmp);
  }
  cout << ans;
}
