n, t = list(map(int, input().split()))



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

ab.sort()



a = []

b = []

for ai, bi in ab:

    a.append(ai)

    b.append(bi)



dp = [[0 for j in range(t+1)] for i in range(n+1)]

prev = [[(0, 0) for j in range(t+1)] for i in range(n+1)]



for i in range(n):

    for j in range(t):

        if j + a[i] <= t-1:

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

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

                prev[i+1][j+a[i]] = (i, j)

        if dp[i+1][j] < dp[i][j]:

            dp[i+1][j] = dp[i][j]

            prev[i+1][j] = (i, j)



happy = dp[n][t-1]

i = n

j = t-1





used = set([])

while i > 0 or j > 0:

    pi, pj = prev[i][j]

    if dp[pi][pj] != dp[i][j]:

        used.add(pi)

    i = pi

    j = pj



unused = []

for i in range(n):

    if i not in used:

        unused.append(b[i])



if len(unused) == 0:

    ans = happy

else:

    ans = happy + max(unused)



print(ans)







n, t = list(map(int, input().split()))



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

ab.sort()



a = []

b = []

for ai, bi in ab:

    a.append(ai)

    b.append(bi)



dp = [[0 for j in range(t+1)] for i in range(n+1)]



for i in range(n):

    for j in range(t):

        if j + a[i] <= t-1:

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

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

        if dp[i+1][j] < dp[i][j]:

            dp[i+1][j] = dp[i][j]



ans = 0



for i in range(n):

    ans = max(ans, dp[i][t-1] + b[i])



print(ans)









n, t = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
a = []
b = []
for ai, bi in ab:
    a.append(ai)
    b.append(bi)
dp = [[0 for j in range(t + 1)] for i in range(n + 1)]
prev = [[(0, 0) for j in range(t + 1)] for i in range(n + 1)]
for i in range(n):
    for j in range(t):
        if j + a[i] <= t - 1:
            if dp[i + 1][j + a[i]] < dp[i][j] + b[i]:
                dp[i + 1][j + a[i]] = dp[i][j] + b[i]
                prev[i + 1][j + a[i]] = (i, j)
        if dp[i + 1][j] < dp[i][j]:
            dp[i + 1][j] = dp[i][j]
            prev[i + 1][j] = (i, j)
happy = dp[n][t - 1]
i = n
j = t - 1
used = set([])
while i > 0 or j > 0:
    pi, pj = prev[i][j]
    if dp[pi][pj] != dp[i][j]:
        used.add(pi)
    i = pi
    j = pj
unused = []
for i in range(n):
    if i not in used:
        unused.append(b[i])
if len(unused) == 0:
    ans = happy
else:
    ans = happy + max(unused)
print(ans)

n, t = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
a = []
b = []
for ai, bi in ab:
    a.append(ai)
    b.append(bi)
dp = [[0 for j in range(t + 1)] for i in range(n + 1)]
for i in range(n):
    for j in range(t):
        if j + a[i] <= t - 1:
            if dp[i + 1][j + a[i]] < dp[i][j] + b[i]:
                dp[i + 1][j + a[i]] = dp[i][j] + b[i]
        if dp[i + 1][j] < dp[i][j]:
            dp[i + 1][j] = dp[i][j]
ans = 0
for i in range(n):
    ans = max(ans, dp[i][t - 1] + b[i])
print(ans)

-prev = [[(0, 0) for j in range(t + 1)] for i in range(n + 1)] -                prev[i + 1][j + a[i]] = (i, j) -            prev[i + 1][j] = (i, j) -happy = dp[n][t - 1] -i = n -j = t - 1 -used = set([]) -while i > 0 or j > 0: -    pi, pj = prev[i][j] -    if dp[pi][pj] != dp[i][j]: -        used.add(pi) -    i = pi -    j = pj -unused = [] +ans = 0 -    if i not in used: -        unused.append(b[i]) -if len(unused) == 0: -    ans = happy -else: -    ans = happy + max(unused) +    ans = max(ans, dp[i][t - 1] + b[i])