#16:25

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

wv = []

for _ in range(n):

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

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

now = [0 for _ in range(t+1)]

for i in range(n):

  w,v = wv[i]

  last = now

  now = []

  for f in range(t):

    if f >= w:

      now.append(max(last[f-w]+v,last[f]))

    else:

      now.append(last[f])

  now.append(max(last[-2]+v,last[-1]))

print((now[-1]))
n,t = list(map(int,input().split()))

dish = []

for _ in range(n):

  a,b = list(map(int,input().split()))

  dish.append([a,b])

dish.sort()

now = [0 for _ in range(t+1)]

for i in range(n):

  a,b = dish[i]

  for d in range(t)[::-1]:

    if d + a < t:

      now[d+a] = max(now[d+a],now[d]+b)

    else:

      now[-1] = max(now[-1],now[d]+b)

  #print(now)

print((now[-1]))
# 16:25
n, t = list(map(int, input().split()))
wv = []
for _ in range(n):
    wv.append(list(map(int, input().split())))
wv.sort(key=lambda x: x[0])
now = [0 for _ in range(t + 1)]
for i in range(n):
    w, v = wv[i]
    last = now
    now = []
    for f in range(t):
        if f >= w:
            now.append(max(last[f - w] + v, last[f]))
        else:
            now.append(last[f])
    now.append(max(last[-2] + v, last[-1]))
print((now[-1]))

n, t = list(map(int, input().split()))
dish = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    dish.append([a, b])
dish.sort()
now = [0 for _ in range(t + 1)]
for i in range(n):
    a, b = dish[i]
    for d in range(t)[::-1]:
        if d + a < t:
            now[d + a] = max(now[d + a], now[d] + b)
        else:
            now[-1] = max(now[-1], now[d] + b)
    # print(now)
print((now[-1]))

-# 16:25 -wv = [] +dish = [] -    wv.append(list(map(int, input().split()))) -wv.sort(key=lambda x: x[0]) +    a, b = list(map(int, input().split())) +    dish.append([a, b]) +dish.sort() -    w, v = wv[i] -    last = now -    now = [] -    for f in range(t): -        if f >= w: -            now.append(max(last[f - w] + v, last[f])) +    a, b = dish[i] +    for d in range(t)[::-1]: +        if d + a < t: +            now[d + a] = max(now[d + a], now[d] + b) -            now.append(last[f]) -    now.append(max(last[-2] + v, last[-1])) +            now[-1] = max(now[-1], now[d] + b) +    # print(now)