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

d=[None]*N

for i in range(N):

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

  d[i]=[a,b]



import numpy as np

d=sorted(d,key=lambda x:x[0])

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

ans=0

for i in range(len(d)):

  t=d[i][0]

  v=d[i][1]

  ans=max(ans,dp.max()+v)

  np.maximum(dp[:-t]+v,dp[t:],out=dp[t:])



print(ans)

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

import numpy as np

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

maxval=0



meals=[None]*N

for i in range(N):

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

  meals[i]=a,b



meals=sorted(meals,key=lambda x:x[0])



for i in range(N):

  a,b=meals[i]

  if maxval<dp[-1]+b:

    maxval=dp[-1]+b

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

  

print(maxval)
N, T = list(map(int, input().split()))
d = [None] * N
for i in range(N):
    a, b = list(map(int, input().split()))
    d[i] = [a, b]
import numpy as np

d = sorted(d, key=lambda x: x[0])
dp = np.zeros(T, dtype=int)
ans = 0
for i in range(len(d)):
    t = d[i][0]
    v = d[i][1]
    ans = max(ans, dp.max() + v)
    np.maximum(dp[:-t] + v, dp[t:], out=dp[t:])
print(ans)

N, T = list(map(int, input().split()))
import numpy as np

dp = np.zeros(T, dtype=int)
maxval = 0
meals = [None] * N
for i in range(N):
    a, b = list(map(int, input().split()))
    meals[i] = a, b
meals = sorted(meals, key=lambda x: x[0])
for i in range(N):
    a, b = meals[i]
    if maxval < dp[-1] + b:
        maxval = dp[-1] + b
    np.maximum(dp[:-a] + b, dp[a:], out=dp[a:])
print(maxval)

-d = [None] * N +import numpy as np + +dp = np.zeros(T, dtype=int) +maxval = 0 +meals = [None] * N -    d[i] = [a, b] -import numpy as np - -d = sorted(d, key=lambda x: x[0]) -dp = np.zeros(T, dtype=int) -ans = 0 -for i in range(len(d)): -    t = d[i][0] -    v = d[i][1] -    ans = max(ans, dp.max() + v) -    np.maximum(dp[:-t] + v, dp[t:], out=dp[t:]) -print(ans) +    meals[i] = a, b +meals = sorted(meals, key=lambda x: x[0]) +for i in range(N): +    a, b = meals[i] +    if maxval < dp[-1] + b: +        maxval = dp[-1] + b +    np.maximum(dp[:-a] + b, dp[a:], out=dp[a:]) +print(maxval)