#include <bits/stdc++.h>
using namespace std;
int n, m, k, d;
pair<int, int> a[200005];
long long sum[200005];
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
  }
  sort(a, a + n);
  long long cur = 0;
  for (int i = 0; i < n; ++i) {
    cur += a[i].second;
    sum[i] = cur;
  }
  long long ans = 0;
  int pos = 0;
  for (int i = 0; i < n; ++i) {
    while (pos < n && a[pos].first - a[i].first < d) pos++;
    long long ret = sum[pos - 1];
    if (i) ret -= sum[i - 1];
    ans = max(ans, ret);
  }
  cout << ans << endl;
  return 0;
}
