#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const long long INF = (long long)(1e17);
const double PI = 3.141592653589793;
long long dx[4] = {-1, 0, 1, 0};
long long dy[4] = {0, 1, 0, -1};
string path = "URDL";
void solve() {
  long long n, d;
  cin >> n >> d;
  vector<pair<long long, long long> > arr(n);
  for (auto& e : arr) cin >> e.first >> e.second;
  sort(arr.begin(), arr.end());
  long long l = 0, r = 0;
  long long temp = 0, ans = 0;
  for (; l < n; temp -= arr[l].second, l++) {
    while (r < n and (arr[r].first - arr[l].first) < d)
      temp += arr[r].second, r++;
    ans = max(ans, temp);
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  solve();
  return 0;
}
