import numpy as np



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



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



for i in range(N):

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

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



print((dp.max()))
import numpy as np



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



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



for i in range(N):

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

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



print((dp.max()))
import numpy as np

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

import numpy as np

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

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