def solve():

  ans = 0

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

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

  A.sort()

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

  for i in range(1,N+1):

    for t in range(1,T+A[-1][0]):

      if t<A[i-1][0] or t>=T+A[i-1][0]:

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

      else:

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

  ans = max(dp[-1])

  return ans

print((solve()))
def solve():

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

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

  A.sort()

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

  for i in range(N):

    for j in range(0,T+1):

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

      if j<T:

        t = min(T,j+A[i][0])

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

  ans = dp[-1][-1]

  return ans

print((solve()))
def solve():
    ans = 0
    N, T = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(N)]
    A.sort()
    dp = [[0] * (T + A[-1][0]) for _ in range(N + 1)]
    for i in range(1, N + 1):
        for t in range(1, T + A[-1][0]):
            if t < A[i - 1][0] or t >= T + A[i - 1][0]:
                dp[i][t] = max(dp[i - 1][t], dp[i][t - 1])
            else:
                dp[i][t] = max(
                    [
                        dp[i - 1][t],
                        dp[i][t - 1],
                        dp[i - 1][t - A[i - 1][0]] + A[i - 1][1],
                    ]
                )
    ans = max(dp[-1])
    return ans


print((solve()))

def solve():
    N, T = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(N)]
    A.sort()
    dp = [[0] * (T + 1) for _ in range(N + 1)]
    for i in range(N):
        for j in range(0, T + 1):
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
            if j < T:
                t = min(T, j + A[i][0])
                dp[i + 1][t] = max(dp[i + 1][t], dp[i][j] + A[i][1])
    ans = dp[-1][-1]
    return ans


print((solve()))

-    ans = 0 -    dp = [[0] * (T + A[-1][0]) for _ in range(N + 1)] -    for i in range(1, N + 1): -        for t in range(1, T + A[-1][0]): -            if t < A[i - 1][0] or t >= T + A[i - 1][0]: -                dp[i][t] = max(dp[i - 1][t], dp[i][t - 1]) -            else: -                dp[i][t] = max( -                    [ -                        dp[i - 1][t], -                        dp[i][t - 1], -                        dp[i - 1][t - A[i - 1][0]] + A[i - 1][1], -                    ] -                ) -    ans = max(dp[-1]) +    dp = [[0] * (T + 1) for _ in range(N + 1)] +    for i in range(N): +        for j in range(0, T + 1): +            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) +            if j < T: +                t = min(T, j + A[i][0]) +                dp[i + 1][t] = max(dp[i + 1][t], dp[i][j] + A[i][1]) +    ans = dp[-1][-1]