#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    long long k;
    if (!(cin >> n >> k)) return 0;

    vector<pair<long long, long long>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    
    sort(a.begin(), a.end());

    long long MAx = 0;
    long long crnt = 0;
    int j = 0;

    for (int i = 0; i < n; i++) {
        while (j < n && a[j].first - a[i].first <= 2 * k) {
            crnt += a[j].second;
            j++;
        }
        MAx = max(MAx, crnt);
        
        crnt -= a[i].second;
    }
    
    cout << MAx << "\n";
    return 0;
}