_, t, *L = list(map(int, open(0).read().split()))

d = [0] * (t + max(L[::2]))

for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):

	for i in range(t + w - 1, w - 1, -1):

		if d[i - w] + v > d[i]:

			d[i] = d[i - w] + v

print((max(d)))

def main():

	_, t, *L = list(map(int, open(0).read().split()))

	d = [0] * (t + max(L[::2]))

	for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):

		for i in range(t + w - 1, w - 1, -1):

			if d[i - w] + v > d[i]:

				d[i] = d[i - w] + v

	print((max(d)))



if __name__=="__main__":

	main()



#vs after contest
_, t, *L = list(map(int, open(0).read().split()))
d = [0] * (t + max(L[::2]))
for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):
    for i in range(t + w - 1, w - 1, -1):
        if d[i - w] + v > d[i]:
            d[i] = d[i - w] + v
print((max(d)))

def main():
    _, t, *L = list(map(int, open(0).read().split()))
    d = [0] * (t + max(L[::2]))
    for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):
        for i in range(t + w - 1, w - 1, -1):
            if d[i - w] + v > d[i]:
                d[i] = d[i - w] + v
    print((max(d)))


if __name__ == "__main__":
    main()
# vs after contest

-_, t, *L = list(map(int, open(0).read().split())) -d = [0] * (t + max(L[::2])) -for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)): -    for i in range(t + w - 1, w - 1, -1): -        if d[i - w] + v > d[i]: -            d[i] = d[i - w] + v -print((max(d))) +def main(): +    _, t, *L = list(map(int, open(0).read().split())) +    d = [0] * (t + max(L[::2])) +    for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)): +        for i in range(t + w - 1, w - 1, -1): +            if d[i - w] + v > d[i]: +                d[i] = d[i - w] + v +    print((max(d))) + + +if __name__ == "__main__": +    main() +# vs after contest