#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define F first
#define S second
#define P system("PAUSE");
#define H return 0;
#define pb push_back
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].F,&a[i].S.F);
a[i].S.S=e;
}
sort(a,a+n);
for(l=0;l<n;o-=a[l].S.F,++l){
while(r<n && abs(a[l].F-a[r].F)<m)o+=a[r].S.F,++r;
if(o>=p[0])p[0]=o,p[1]=l,p[2]=r;
}
for(i=p[1];i<p[2];++i)ot.pb(a[i].S.S);
cout<<p[0]<<"\n";
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPG1hdGguaD4KI2luY2x1ZGU8YWxnb3JpdGhtPgojaW5jbHVkZTxzdGRpby5oPgojaW5jbHVkZTxtYXA+CiNpbmNsdWRlPHZlY3Rvcj4KI2luY2x1ZGU8c2V0PgojaW5jbHVkZTxpb21hbmlwPgojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIFAgc3lzdGVtKCJQQVVTRSIpOwojZGVmaW5lIEggcmV0dXJuIDA7CiNkZWZpbmUgcGIgcHVzaF9iYWNrCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGxvbmcgbG9uZyBBPTEwMDAwMDAwMDAwMDAwMExMLE49MjI4MjI4OwoKY2hhciBlWzIxXTsKdmVjdG9yPHN0cmluZz4gb3Q7CnBhaXI8aW50LHBhaXI8aW50LHN0cmluZz4gPiBhW05dOwpsb25nIGxvbmcgbyxwWzNdPXstMSwtMSwtMX07CmludCBpLGosbCxyLG4sbTsKCmludCBtYWluKCl7CgljaW4+Pm4+Pm07Cglmb3IoaT0wO2k8bjsrK2kpewoJICAgIHNjYW5mKCIlZCV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