rt
#include <bits/stdc++.h>
#define int long long
using namespace std;
int sum[10000000],a[10000000],homo = 1,n,m,x,y,ans;
signed main()
{
cin >> n >> m;
for(int i = 1;i <= n;++i){
cin >> x >> y;
a[x] += y;
homo = max(homo,x);
}
for(int i = 1;i <= homo;++i){
sum[i] = sum[i - 1]+a[i];
}
ans = -11;
for(int i = 1;i <= homo;++i){
ans = max(ans,sum[i] - sum[i - m]);
}
cout << ans;
return 0;
}