#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <string.h>
using namespace std;
typedef long long LL;
int main() {
int n, d;
cin >> n >> d;
vector<pair<int,int>> v(n);
for (int i = 0; i < n; i++)
{
int m, f;
cin >> m >> f;
v[i] = make_pair(m, f);
}
sort(v.begin(), v.end());
vector<LL> t(n);
for (int i = 0; i < n; i++)
{
t[i] = v[i].second;
}
for (int i = n-2; i >= 0; i--)
{
t[i] += t[i+1];
}
LL best = 0;
for (int i = 0; i < n; i++)
{
int x = v[i].first+d-1;
pair<int,int> z = make_pair(x, 2000000000);
int p = upper_bound(v.begin(), v.end(), z) - v.begin();
LL ff = (p == n) ? t[i] : t[i]-t[p];
best = max(ff, best);
}
cout << best << endl;
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxkZXF1ZT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPG51bWVyaWM+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPHN0cmluZy5oPgoKdXNpbmcgbmFt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