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.
import sys, io, os
import math
import bisect
import heapq
import string
import re
from decimal import *
from collections import defaultdict,Counter,deque
input = sys.stdin.readline
 
def I():
    return input()
 
def II():
    return int(input())
 
def MII():
    return map(int, input().split())
 
def LI():
    return list(input().split())
 
def LII():
    return list(map(int, input().split()))
 
def GMI():
    return map(lambda x: int(x) - 1, input().split())
 
def LGMI():
    return list(map(lambda x: int(x) - 1, input().split()))
 
def WRITE(out):
  return print('\n'.join(map(str, out)))
 
def WS(out):
  return print(' '.join(map(str, out)))
 
def WNS(out):
  return print(''.join(map(str, out)))

def WSNOPRINT(out):
  return ''.join(map(str, out))


'''
0 75 100
100 6 20
100 106 126
'''
def solve():
    n, d = MII()
    a = defaultdict(int)
    for _ in range(n):
        m, f = MII()
        a[m] += f

    p = [0]
    l = [-1]
    for k in sorted(a.keys()):
        l.append(k)
        if not p:
            p.append(a[k])
        else:
            p.append(p[-1] + a[k])

    ans = 0
    for i in range(1, len(l)):
        ldx = bisect.bisect_left(l, l[i]-d)
        ldx = max(0, ldx-1)
        ans = max(ans, p[i]-p[ldx])
    print(ans)

def main():
    solve()

main()
