# 12892번. 생일선물
importsysinput=sys.stdin.readlinen,d=map(int,input().split())nList=[0foriinrange(n)]foriinrange(n):nList[i]=list(map(int,input().split()))nList.sort()idx=[]maxhappy=nList[0][1]s=maxhappy# 합을 바꿀 변수
j=0# sliding
foriinrange(1,n):s+=nList[i][1]whilenList[i][0]-nList[j][0]>=d:s-=nList[j][1]j+=1maxhappy=max(maxhappy,s)# 최대값 비교
print(maxhappy)