#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  while (a && b) a > b ? a %= b : b %= a;
  return a + b;
}
long long int lcm(long long int a, long long int b) {
  return (max(a, b) / gcd(a, b)) * min(a, b);
}
long long int power(long long int a, long long int b) {
  long long int res = 1;
  while (b != 0) {
    if (b % 2 != 0) {
      res = (res * a) % 1000000007;
      b--;
    } else {
      a = (a * a) % 1000000007;
      b /= 2;
    }
  }
  return res;
}
long long int f[100005];
long long int n, d;
pair<long long int, long long int> v[100005];
long long int Find(long long int u) {
  long long int l = 0, r = n;
  while (l < r) {
    long long int m = (l + r + 1) / 2;
    if (v[m].first > u)
      r = m - 1;
    else
      l = m;
  }
  return l;
}
int main() {
  ios::sync_with_stdio(0);
  ;
  long long int i, j, k, c = 0, m, t, l, r, x, y, w, low, high, mid;
  string s;
  cin >> n >> d;
  vector<long long int> a, b;
  for (i = 1; i <= n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v + 1, v + n + 1);
  for (i = 1; i <= n; i++) {
    f[i] = f[i - 1] + v[i].second;
    c = max(c, f[i] - f[Find(v[i].first - d)]);
  }
  cout << c;
  return 0;
}
