from numpy import*

f=lambda:list(map(int,input().split()))

N,W=f()

J=arange(0,W+1,1,'i8')

T=J*0

exec('w,v=f();T=maximum(T,(T[J-w]+v)*(J>=w));'*N)

print((T[-1]))
from numpy import*

f=lambda:list(map(int,input().split()))

N,W=f()

T=zeros(W+1,'i8')

exec('w,v=f();T[w:]=maximum(T[w:],T[:-w]+v);'*N)

print((T[-1]))
from numpy import *

f = lambda: list(map(int, input().split()))
N, W = f()
J = arange(0, W + 1, 1, "i8")
T = J * 0
exec("w,v=f();T=maximum(T,(T[J-w]+v)*(J>=w));" * N)
print((T[-1]))

from numpy import *

f = lambda: list(map(int, input().split()))
N, W = f()
T = zeros(W + 1, "i8")
exec("w,v=f();T[w:]=maximum(T[w:],T[:-w]+v);" * N)
print((T[-1]))

-J = arange(0, W + 1, 1, "i8") -T = J * 0 -exec("w,v=f();T=maximum(T,(T[J-w]+v)*(J>=w));" * N) +T = zeros(W + 1, "i8") +exec("w,v=f();T[w:]=maximum(T[w:],T[:-w]+v);" * N)