import numpy as np  



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



dp = np.zeros(w+1)



for i in range(n):

    weight, value = list(map(int, input().split()))



    dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value) 



print((int(dp[-1])))


import numpy as np  



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



dp = np.array([0] * (w+1)) 



for i in range(n):

    weight, value = list(map(int, input().split()))



    dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value) 



print((int(dp[-1])))
import numpy as np

n, w = list(map(int, input().split()))
dp = np.zeros(w + 1)
for i in range(n):
    weight, value = list(map(int, input().split()))
    dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value)
print((int(dp[-1])))

import numpy as np

n, w = list(map(int, input().split()))
dp = np.array([0] * (w + 1))
for i in range(n):
    weight, value = list(map(int, input().split()))
    dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value)
print((int(dp[-1])))

-dp = np.zeros(w + 1) +dp = np.array([0] * (w + 1))