N, T, *AB = list(map(int, open(0).read().split()))



dp = [0] * (T + max(AB[::2]))

for w, v in sorted(zip(*[iter(AB)] * 2)):

    for i in reversed(list(range(T))):

        dp[i + w] = max(dp[i + w], dp[i] + v)



print((max(dp)))

def main():

    N, T, *AB = list(map(int, open(0).read().split()))



    dp = [0] * (T + max(AB[::2]))

    for w, v in sorted(zip(*[iter(AB)] * 2)):

        for i in reversed(list(range(T))):

            dp[i + w] = max(dp[i + w], dp[i] + v)



    print((max(dp)))



main()
N, T, *AB = list(map(int, open(0).read().split()))
dp = [0] * (T + max(AB[::2]))
for w, v in sorted(zip(*[iter(AB)] * 2)):
    for i in reversed(list(range(T))):
        dp[i + w] = max(dp[i + w], dp[i] + v)
print((max(dp)))

def main():
    N, T, *AB = list(map(int, open(0).read().split()))
    dp = [0] * (T + max(AB[::2]))
    for w, v in sorted(zip(*[iter(AB)] * 2)):
        for i in reversed(list(range(T))):
            dp[i + w] = max(dp[i + w], dp[i] + v)
    print((max(dp)))


main()

-N, T, *AB = list(map(int, open(0).read().split())) -dp = [0] * (T + max(AB[::2])) -for w, v in sorted(zip(*[iter(AB)] * 2)): -    for i in reversed(list(range(T))): -        dp[i + w] = max(dp[i + w], dp[i] + v) -print((max(dp))) +def main(): +    N, T, *AB = list(map(int, open(0).read().split())) +    dp = [0] * (T + max(AB[::2])) +    for w, v in sorted(zip(*[iter(AB)] * 2)): +        for i in reversed(list(range(T))): +            dp[i + w] = max(dp[i + w], dp[i] + v) +    print((max(dp))) + + +main()