#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long calpowof2(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    long long ans = calpowof2(a, b / 2);
    return (ans % mod * ans % mod) % mod;
  }
  long long ans = calpowof2(a, b - 1);
  return (a % mod * ans % mod) % mod;
}
void solve() {
  long long i, j, n, t, m, k, ct = 0, sum = 0, flag = 0;
  cin >> n >> k;
  vector<pair<long long, long long> > v1;
  for (long long i = (0); i < (n); i++) {
    cin >> j >> m;
    v1.push_back({j, m});
  }
  sort(v1.begin(), v1.end());
  long long start_ptr = 0;
  sum = v1[0].second;
  long long mx = INT_MIN;
  mx = sum;
  for (long long i = (1); i < (n); i++) {
    if (v1[i].first - v1[start_ptr].first < k) {
      sum += v1[i].second;
      mx = max(sum, mx);
    } else {
      sum -= v1[start_ptr].second;
      start_ptr++;
      i--;
    }
  }
  cout << mx;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  cerr << endl << clock() * 1000.0 / CLOCKS_PER_SEC << 'm' << 's';
  return 0;
}
