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

import numpy as np

dp=np.zeros(W+1,dtype=int)

for i in range(N):

  w,v=list(map(int,input().split()))

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

print((dp.max()))

import sys

readline = sys.stdin.readline



import numpy as np



N,W = list(map(int,readline().split()))



dp = np.zeros(W + 1, dtype = int)

for i in range(N):

  w,v = list(map(int,readline().split()))

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

  

print((max(dp)))
N, W = list(map(int, input().split()))
import numpy as np

dp = np.zeros(W + 1, dtype=int)
for i in range(N):
    w, v = list(map(int, input().split()))
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print((dp.max()))

import sys

readline = sys.stdin.readline
import numpy as np

N, W = list(map(int, readline().split()))
dp = np.zeros(W + 1, dtype=int)
for i in range(N):
    w, v = list(map(int, readline().split()))
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print((max(dp)))

-N, W = list(map(int, input().split())) +import sys + +readline = sys.stdin.readline +N, W = list(map(int, readline().split())) -    w, v = list(map(int, input().split())) +    w, v = list(map(int, readline().split())) -print((dp.max())) +print((max(dp)))