def main():

    N, T = list(map(int, input().split()))

    AB = [list(map(int, input().split())) for _ in range(N)]



    dp = [-1] * (T + 3000)

    dp[0] = 0

    c = 0

    for a, b in sorted(AB):

        for j in range(c, -1, -1):

            if dp[j] == -1:

                continue

            t = dp[j] + b

            if dp[j + a] < t:

                dp[j + a] = t

        c = min(c + a, T - 1)

    print((max(dp)))





main()

def main():

    N, T = list(map(int, input().split()))

    AB = [list(map(int, input().split())) for _ in range(N)]



    dp = [-1] * (T + 3000)

    dp[0] = 0

    for a, b in sorted(AB):

        for i in range(T - 1, -1, -1):

            if dp[i] == -1:

                continue

            if dp[i + a] < dp[i] + b:

                dp[i + a] = dp[i] + b

    print((max(dp)))





main()

def main():
    N, T = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(N)]
    dp = [-1] * (T + 3000)
    dp[0] = 0
    c = 0
    for a, b in sorted(AB):
        for j in range(c, -1, -1):
            if dp[j] == -1:
                continue
            t = dp[j] + b
            if dp[j + a] < t:
                dp[j + a] = t
        c = min(c + a, T - 1)
    print((max(dp)))


main()

def main():
    N, T = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(N)]
    dp = [-1] * (T + 3000)
    dp[0] = 0
    for a, b in sorted(AB):
        for i in range(T - 1, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + a] < dp[i] + b:
                dp[i + a] = dp[i] + b
    print((max(dp)))


main()

-    c = 0 -        for j in range(c, -1, -1): -            if dp[j] == -1: +        for i in range(T - 1, -1, -1): +            if dp[i] == -1: -            t = dp[j] + b -            if dp[j + a] < t: -                dp[j + a] = t -        c = min(c + a, T - 1) +            if dp[i + a] < dp[i] + b: +                dp[i + a] = dp[i] + b