import sys

input=sys.stdin.readline

def knapsack(N,W,weight,value):

  dp=[[float('inf') for i in range(W+1)] for j in range(N+1)]

  for i in range(W+1):

    dp[0][i]=0

 

  for i in range(N):

    for w in range(W+1):

      if weight[i]<=w:

        if dp[i][w-weight[i]]+value[i]>dp[i][w]:

          dp[i+1][w]=dp[i][w-weight[i]]+value[i]

        else:

          dp[i+1][w]=dp[i][w]

      else:

        dp[i+1][w]=dp[i][w]

  return dp

 

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

l=[list(map(int,input().split())) for i in range(n)]

l.sort()

a=[];b=[]

for i in range(n):

  a.append(l[i][0])

  b.append(l[i][1])

dp=knapsack(n,t-1,a,b)

ans=[]

for i in range(n):

  if i!=n:

    ans.append(dp[i][t-1]+b[i])

  else:

    ans.append(dp[n][t])

print((max(ans)))
import sys

input=sys.stdin.readline

def knapsack(N,W,weight,value):

  dp=[[999999999999 for i in range(W+1)] for j in range(N+1)]

  for i in range(W+1):

    dp[0][i]=0

 

  for i in range(N):

    for w in range(W+1):

      if weight[i]<=w:

        if dp[i][w-weight[i]]+value[i]>dp[i][w]:

          dp[i+1][w]=dp[i][w-weight[i]]+value[i]

        else:

          dp[i+1][w]=dp[i][w]

      else:

        dp[i+1][w]=dp[i][w]

  return dp

 

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

l=[list(map(int,input().split())) for i in range(n)]

l.sort()

a=[];b=[]

for i in range(n):

  a.append(l[i][0])

  b.append(l[i][1])

dp=knapsack(n,t-1,a,b)

ans=[]

for i in range(n):

  if i!=n:

    ans.append(dp[i][t-1]+b[i])

  else:

    ans.append(dp[n][t])

print((max(ans)))
import sys

input = sys.stdin.readline


def knapsack(N, W, weight, value):
    dp = [[float("inf") for i in range(W + 1)] for j in range(N + 1)]
    for i in range(W + 1):
        dp[0][i] = 0
    for i in range(N):
        for w in range(W + 1):
            if weight[i] <= w:
                if dp[i][w - weight[i]] + value[i] > dp[i][w]:
                    dp[i + 1][w] = dp[i][w - weight[i]] + value[i]
                else:
                    dp[i + 1][w] = dp[i][w]
            else:
                dp[i + 1][w] = dp[i][w]
    return dp


n, t = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
l.sort()
a = []
b = []
for i in range(n):
    a.append(l[i][0])
    b.append(l[i][1])
dp = knapsack(n, t - 1, a, b)
ans = []
for i in range(n):
    if i != n:
        ans.append(dp[i][t - 1] + b[i])
    else:
        ans.append(dp[n][t])
print((max(ans)))

import sys

input = sys.stdin.readline


def knapsack(N, W, weight, value):
    dp = [[999999999999 for i in range(W + 1)] for j in range(N + 1)]
    for i in range(W + 1):
        dp[0][i] = 0
    for i in range(N):
        for w in range(W + 1):
            if weight[i] <= w:
                if dp[i][w - weight[i]] + value[i] > dp[i][w]:
                    dp[i + 1][w] = dp[i][w - weight[i]] + value[i]
                else:
                    dp[i + 1][w] = dp[i][w]
            else:
                dp[i + 1][w] = dp[i][w]
    return dp


n, t = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
l.sort()
a = []
b = []
for i in range(n):
    a.append(l[i][0])
    b.append(l[i][1])
dp = knapsack(n, t - 1, a, b)
ans = []
for i in range(n):
    if i != n:
        ans.append(dp[i][t - 1] + b[i])
    else:
        ans.append(dp[n][t])
print((max(ans)))

-    dp = [[float("inf") for i in range(W + 1)] for j in range(N + 1)] +    dp = [[999999999999 for i in range(W + 1)] for j in range(N + 1)]