import sys

input = sys.stdin.readline



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

d = []

for _ in range(N):

  d.append(list(map(int, input().split())))

d.sort(key = lambda x: x[0])

dp = [[0] * (T + 1) for _ in range(N + 1)]

res = 0

for i in range(N):

  for j in range(T):

    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

    if j + d[i][0] <= T: dp[i + 1][j + d[i][0]] = max(dp[i + 1][j + d[i][0]], dp[i][j] + d[i][1])

    else: dp[i + 1][T] = max(dp[i + 1][T], dp[i][j] + d[i][1])

  #print(dp[i])

for i in range(N + 1):

  res = max(max(dp[i]), res)

print(res)
import sys

input = sys.stdin.readline

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

a = []

for _ in range(N):

  w, v = list(map(int, input().split()))

  a.append((w, v))

a.sort()

dp = [[0] * (T + 1) for _ in range(N + 1)]

for i in range(N):

  w, v = a[i]

  for j in range(T):

    if j + w >= T:

      dp[i + 1][T] = max(dp[i + 1][T], dp[i][j] + v)

    else:

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

    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

  dp[i + 1][T] = max(dp[i + 1][T], dp[i][T])

print((max(dp[-1])))
import sys

input = sys.stdin.readline
N, T = list(map(int, input().split()))
d = []
for _ in range(N):
    d.append(list(map(int, input().split())))
d.sort(key=lambda x: x[0])
dp = [[0] * (T + 1) for _ in range(N + 1)]
res = 0
for i in range(N):
    for j in range(T):
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        if j + d[i][0] <= T:
            dp[i + 1][j + d[i][0]] = max(dp[i + 1][j + d[i][0]], dp[i][j] + d[i][1])
        else:
            dp[i + 1][T] = max(dp[i + 1][T], dp[i][j] + d[i][1])
    # print(dp[i])
for i in range(N + 1):
    res = max(max(dp[i]), res)
print(res)

import sys

input = sys.stdin.readline
N, T = list(map(int, input().split()))
a = []
for _ in range(N):
    w, v = list(map(int, input().split()))
    a.append((w, v))
a.sort()
dp = [[0] * (T + 1) for _ in range(N + 1)]
for i in range(N):
    w, v = a[i]
    for j in range(T):
        if j + w >= T:
            dp[i + 1][T] = max(dp[i + 1][T], dp[i][j] + v)
        else:
            dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
    dp[i + 1][T] = max(dp[i + 1][T], dp[i][T])
print((max(dp[-1])))

-d = [] +a = [] -    d.append(list(map(int, input().split()))) -d.sort(key=lambda x: x[0]) +    w, v = list(map(int, input().split())) +    a.append((w, v)) +a.sort() -res = 0 +    w, v = a[i] +        if j + w >= T: +            dp[i + 1][T] = max(dp[i + 1][T], dp[i][j] + v) +        else: +            dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v) -        if j + d[i][0] <= T: -            dp[i + 1][j + d[i][0]] = max(dp[i + 1][j + d[i][0]], dp[i][j] + d[i][1]) -        else: -            dp[i + 1][T] = max(dp[i + 1][T], dp[i][j] + d[i][1]) -    # print(dp[i]) -for i in range(N + 1): -    res = max(max(dp[i]), res) -print(res) +    dp[i + 1][T] = max(dp[i + 1][T], dp[i][T]) +print((max(dp[-1])))