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

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



dp1 = [[0 for n in range(N+1)] for t in range(T+1)] #dp1[t][n] := (data[:n]の中からtまでに食べ切る範囲で美味しく）

dp2 = [[0 for n in range(N+1)] for t in range(T+1)] #dp1[t][n] := (data[:n]の中からt-1までに注文する範囲で美味しく)





for t in range(1,T+1):

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

        if t-data[n-1][0] >= 0:

            dp1[t][n] = max(dp1[t][n-1],dp1[t-data[n-1][0]][n-1]+data[n-1][1])

            dp2[t][n] = max(dp2[t][n-1],dp2[t-data[n-1][0]][n-1]+data[n-1][1],dp1[t-1][n-1]+data[n-1][1])

        else:

            dp1[t][n] = dp1[t][n-1]

            dp2[t][n] = max(dp2[t][n-1],dp1[t-1][n-1]+data[n-1][1])





print((dp2[T][N]))
import sys

input = sys.stdin.readline

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

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



dp1 = [[0]*(N+1) for t in range(T+1)] #dp1[t][n] := (data[:n]の中からtまでに食べ切る範囲で美味しく）

dp2 = [[0]*(N+1) for t in range(T+1)] #dp1[t][n] := (data[:n]の中からt-1までに注文する範囲で美味しく)





for t in range(1,T+1):

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

        if t-data[n-1][0] >= 0:

            dp1[t][n] = max(dp1[t][n-1],dp1[t-data[n-1][0]][n-1]+data[n-1][1])

            dp2[t][n] = max(dp2[t][n-1],dp2[t-data[n-1][0]][n-1]+data[n-1][1],dp1[t-1][n-1]+data[n-1][1])

        else:

            dp1[t][n] = dp1[t][n-1]

            dp2[t][n] = max(dp2[t][n-1],dp1[t-1][n-1]+data[n-1][1])





print((dp2[T][N]))
N, T = list(map(int, input().split()))
data = [list(map(int, input().split())) for _ in range(N)]
dp1 = [
    [0 for n in range(N + 1)] for t in range(T + 1)
]  # dp1[t][n] := (data[:n]の中からtまでに食べ切る範囲で美味しく）
dp2 = [
    [0 for n in range(N + 1)] for t in range(T + 1)
]  # dp1[t][n] := (data[:n]の中からt-1までに注文する範囲で美味しく)
for t in range(1, T + 1):
    for n in range(1, N + 1):
        if t - data[n - 1][0] >= 0:
            dp1[t][n] = max(
                dp1[t][n - 1], dp1[t - data[n - 1][0]][n - 1] + data[n - 1][1]
            )
            dp2[t][n] = max(
                dp2[t][n - 1],
                dp2[t - data[n - 1][0]][n - 1] + data[n - 1][1],
                dp1[t - 1][n - 1] + data[n - 1][1],
            )
        else:
            dp1[t][n] = dp1[t][n - 1]
            dp2[t][n] = max(dp2[t][n - 1], dp1[t - 1][n - 1] + data[n - 1][1])
print((dp2[T][N]))

import sys

input = sys.stdin.readline
N, T = list(map(int, input().split()))
data = [list(map(int, input().split())) for _ in range(N)]
dp1 = [
    [0] * (N + 1) for t in range(T + 1)
]  # dp1[t][n] := (data[:n]の中からtまでに食べ切る範囲で美味しく）
dp2 = [
    [0] * (N + 1) for t in range(T + 1)
]  # dp1[t][n] := (data[:n]の中からt-1までに注文する範囲で美味しく)
for t in range(1, T + 1):
    for n in range(1, N + 1):
        if t - data[n - 1][0] >= 0:
            dp1[t][n] = max(
                dp1[t][n - 1], dp1[t - data[n - 1][0]][n - 1] + data[n - 1][1]
            )
            dp2[t][n] = max(
                dp2[t][n - 1],
                dp2[t - data[n - 1][0]][n - 1] + data[n - 1][1],
                dp1[t - 1][n - 1] + data[n - 1][1],
            )
        else:
            dp1[t][n] = dp1[t][n - 1]
            dp2[t][n] = max(dp2[t][n - 1], dp1[t - 1][n - 1] + data[n - 1][1])
print((dp2[T][N]))

+import sys + +input = sys.stdin.readline -    [0 for n in range(N + 1)] for t in range(T + 1) +    [0] * (N + 1) for t in range(T + 1) -    [0 for n in range(N + 1)] for t in range(T + 1) +    [0] * (N + 1) for t in range(T + 1)