import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



import numpy as np



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

m = list(map(int,read().split()))

WV = list(zip(m,m))



# 重さ -> 最大価値



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



for w,v in WV:

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



answer = dp.max()

print(answer)
import sys

import numpy as np



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



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

WV = np.array(read().split(), np.int64)



W = WV[::2]

V = WV[1::2]



# weight -> value

dp = np.zeros(lim + 1, np.int64)

for w, v in zip(W, V):

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

print((dp.max()))
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N, W = list(map(int, readline().split()))
m = list(map(int, read().split()))
WV = list(zip(m, m))
# 重さ -> 最大価値
dp = np.zeros(W + 1, np.int64)
for w, v in WV:
    np.maximum(dp[w:], dp[:-w].copy() + v, out=dp[w:])
answer = dp.max()
print(answer)

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, lim = list(map(int, readline().split()))
WV = np.array(read().split(), np.int64)
W = WV[::2]
V = WV[1::2]
# weight -> value
dp = np.zeros(lim + 1, np.int64)
for w, v in zip(W, V):
    np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])
print((dp.max()))

+import numpy as np -import numpy as np - -N, W = list(map(int, readline().split())) -m = list(map(int, read().split())) -WV = list(zip(m, m)) -# 重さ -> 最大価値 -dp = np.zeros(W + 1, np.int64) -for w, v in WV: -    np.maximum(dp[w:], dp[:-w].copy() + v, out=dp[w:]) -answer = dp.max() -print(answer) +N, lim = list(map(int, readline().split())) +WV = np.array(read().split(), np.int64) +W = WV[::2] +V = WV[1::2] +# weight -> value +dp = np.zeros(lim + 1, np.int64) +for w, v in zip(W, V): +    np.maximum(dp[w:], dp[:-w] + v, out=dp[w:]) +print((dp.max()))