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

AB = []

for i in range(N):

  A, B = list(map(int, input().split()))

  AB.append([A, B])



AB.sort()



dp = [[0 for t in range(T)] for i in range(N+1)]



ans = 0

for i, ab in enumerate(AB):

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

  for t in range(T):

    if t < ab[0]:

      dp[i+1][t] = dp[i][t]

    else:

      dp[i+1][t] = max(dp[i][t-ab[0]] + ab[1], dp[i][t])



print(ans)

import numpy as np



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

AB = []

for i in range(N):

  A, B = list(map(int, input().split()))

  AB.append([A, B])



AB.sort()



dp = np.zeros(T, dtype=int)



ans = 0

for a, b in AB:

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

  dp[a:] = np.maximum(dp[a:], dp[:-a] + b)



print(ans)
N, T = list(map(int, input().split()))
AB = []
for i in range(N):
    A, B = list(map(int, input().split()))
    AB.append([A, B])
AB.sort()
dp = [[0 for t in range(T)] for i in range(N + 1)]
ans = 0
for i, ab in enumerate(AB):
    ans = max(ans, dp[i][T - 1] + ab[1])
    for t in range(T):
        if t < ab[0]:
            dp[i + 1][t] = dp[i][t]
        else:
            dp[i + 1][t] = max(dp[i][t - ab[0]] + ab[1], dp[i][t])
print(ans)

import numpy as np

N, T = list(map(int, input().split()))
AB = []
for i in range(N):
    A, B = list(map(int, input().split()))
    AB.append([A, B])
AB.sort()
dp = np.zeros(T, dtype=int)
ans = 0
for a, b in AB:
    ans = max(ans, dp[-1] + b)
    dp[a:] = np.maximum(dp[a:], dp[:-a] + b)
print(ans)

+import numpy as np + -dp = [[0 for t in range(T)] for i in range(N + 1)] +dp = np.zeros(T, dtype=int) -for i, ab in enumerate(AB): -    ans = max(ans, dp[i][T - 1] + ab[1]) -    for t in range(T): -        if t < ab[0]: -            dp[i + 1][t] = dp[i][t] -        else: -            dp[i + 1][t] = max(dp[i][t - ab[0]] + ab[1], dp[i][t]) +for a, b in AB: +    ans = max(ans, dp[-1] + b) +    dp[a:] = np.maximum(dp[a:], dp[:-a] + b)