#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int mod = (int)1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;
pair<long long, long long> p[maxn];
int main() {
  {
    srand(time(0));
    const string file = "";
    if (!file.empty()) {
      freopen((file + ".in").c_str(), "r", stdin);
      freopen((file + ".out").c_str(), "w", stdout);
    }
  }
  long long n, d;
  scanf("%I64d%I64d", &n, &d);
  for (int i = 0; i < n; i++) {
    scanf("%I64d%I64d", &p[i].first, &p[i].second);
  }
  sort(&p[0], &p[n]);
  long long ans = 0, mans = 0;
  for (int i = 0, f = 0; i < n; i++) {
    while (f < n && p[f].first - p[i].first < d) {
      ans += p[f++].second;
    }
    mans = max(mans, ans);
    ans -= p[i].second;
  }
  printf("%I64d", mans);
  return (0);
}
