#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 228228;
char e[21];
vector<string> ot;
pair<int, pair<int, string> > a[N];
long long o, p[3] = {-1, -1, -1};
int i, j, l, r, n, m;
int main() {
  cin >> n >> m;
  for (i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second.first);
    a[i].second.second = e;
  }
  sort(a, a + n);
  for (l = 0; l < n; o -= a[l].second.first, ++l) {
    while (r < n && abs(a[l].first - a[r].first) < m)
      o += a[r].second.first, ++r;
    if (o >= p[0]) p[0] = o, p[1] = l, p[2] = r;
  }
  for (i = p[1]; i < p[2]; ++i) ot.push_back(a[i].second.second);
  cout << p[0] << "\n";
}
