Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. 

Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least *d* units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
The first line of the input contains two space-separated integers, *n* and *d* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dbb69b02906f9aa8e36ba613133328a16da7cfcb.png" style="max-width: 100.0%;max-height: 100.0%;"/>) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.

Next *n* lines contain the descriptions of Kefa's friends, the (*i* + 1)-th line contains the description of the *i*-th friend of type *m*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i*</sub> (0 ≤ *m*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>) — the amount of money and the friendship factor, respectively.
def ii():
    return int(input())
def li():
    return list(map(int,input().split()))
def si():
    return input()
def ti():
    return map(int,input().split())
def di():
    return deque((map(int,input().split())))
from bisect import bisect_left,bisect_right
from collections import deque,defaultdict
from math import *
def prefixsum(l,n):
    array=[l[0]]
    for i in range(1,n):
        array.append(array[-1]+l[i])
    return array
def suffixsum(l,n):
    array=[0]*n
    temperory=0
    for i in range(n):
        temperory+=l[n-1-i]
        array[n-1-i]=temperory
    return array
def prime(x):
    if x==1:
        return(0)
    elif x==2:
        return(1)
    else:
        t=(sqrt(x))+1
        t=int(t)
        for i in range(2,t):
            if x%i==0:
                return(0)
        else:
            return(1)
def prefixmax(l,n):
    array=[l[0]]
    for i in range(1,n):
        array.append(max(array[-1],l[i]))
    return array
def prefixmin(l,n):
    array=[l[0]]
    for i in range(1,n):
        array.append(min(array[-1],l[i]))
    return array
def BinarySearch(a, x):
 
    i = bisect_left(a, x)
 
    if i != len(a) and a[i] == x:
 
        return i
 
    else:
 
        return -1
def sortremoveDuplicates(arr, n):
    if n == 0 or n == 1:
        return arr
 
    temp = []
    j = 0
    for i in range(0, n-1):
        if arr[i] != arr[i+1]:
            temp += [arr[i]]
            j += 1
    temp += [arr[n-1]]
    return temp
def decimalToBinary(n):
    return bin(n).replace("0b", "")
def ato1(chr):
    return ord(chr)-ord("a")
def permutationindex(l,n):
    arr=[0]*(n)
    for i in range(n):
        arr[l[i]-1]=i
    return arr
def issubsequence(s1, s2):
 
    n, m = len(s1), len(s2)
    i, j = 0, 0
    while (i < n and j < m):
        if (s1[i] == s2[j]):
            i += 1
        j += 1
 
    # If i reaches end of s1,that mean we found all
    # characters of s1 in s2,
    # so s1 is subsequence of s2, else not
    return i == n 
def primef(n):
    l1=[]
    i=2
    while i*i<=n:
        if n%i!=0:
            i+=1
        else:
            l1.append(i)
            n//=i
    if n>1:
        l1.append(n)
    return l1
def factors(n):
    l=[1]
    for i in range(2,n+1):
        if n%i==0:
            l.append(i)
    return l
def sumi1(n):
    ans=0
    while n>0:
        ans+=n%10
        n//=10
    return ans
"""mod=7+10**9
for _ in range (ii()):
    n,m=ti()
    l=li()
    l.sort()
    l1=sortremoveDuplicates(l,n)
    ans=0
    for i in range(n):
        j=BinarySearch(l1,l[i])
        x=bisect_right(l1,l[i]+m-1)
        if x-j<m:
            ans+=0
        else:
            z=factorial(x-j-1)
            z//=factorial(m-1)
            z//=factorial(x-j-m)
            z%=mod
            ans+=z
            ans%=mod
    print(ans)"""
for _ in range(1):
    n,d=ti()
    d-=1
    l=[]
    l1=[0]*(n+1)
    for i in range(n):
        l.append(li())
    l.sort()
    ans=0
    for i in range(n):
        l1[i+1]=l[i][1]+l1[i]
    for i in range(n):
        x=bisect_left(l,[l[i][0]+d,10**9])
        ans=max(ans,l1[x]-l1[i])
    print(ans)