# coding: utf-8

# Your code here!

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



l=[-1]*(W+1)

l[0]=0

dp=l[:]



for i in range(N):

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

    for index,item in enumerate(l):

        if item!=-1 and W>=index+w:

            dp[index+w]=max(item+v,l[index+w])

    l=dp[:]

print((max(l)))

# coding: utf-8

# Your code here!

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



jwels=[]



for _ in range(N):

    jwels.append(list(map(int,input().split())))



dp=[-1]*(W+1)

dp[0]=0



for w,v in jwels:

    for i in range(W+1)[::-1]:

        if dp[i]!=-1 and i+w<=W:

            dp[i+w]=max(dp[i]+v,dp[i+w])

            

print((max(dp)))



# coding: utf-8
# Your code here!
N, W = list(map(int, input().split()))
l = [-1] * (W + 1)
l[0] = 0
dp = l[:]
for i in range(N):
    w, v = list(map(int, input().split()))
    for index, item in enumerate(l):
        if item != -1 and W >= index + w:
            dp[index + w] = max(item + v, l[index + w])
    l = dp[:]
print((max(l)))

# coding: utf-8
# Your code here!
N, W = list(map(int, input().split()))
jwels = []
for _ in range(N):
    jwels.append(list(map(int, input().split())))
dp = [-1] * (W + 1)
dp[0] = 0
for w, v in jwels:
    for i in range(W + 1)[::-1]:
        if dp[i] != -1 and i + w <= W:
            dp[i + w] = max(dp[i] + v, dp[i + w])
print((max(dp)))

-l = [-1] * (W + 1) -l[0] = 0 -dp = l[:] -for i in range(N): -    w, v = list(map(int, input().split())) -    for index, item in enumerate(l): -        if item != -1 and W >= index + w: -            dp[index + w] = max(item + v, l[index + w]) -    l = dp[:] -print((max(l))) +jwels = [] +for _ in range(N): +    jwels.append(list(map(int, input().split()))) +dp = [-1] * (W + 1) +dp[0] = 0 +for w, v in jwels: +    for i in range(W + 1)[::-1]: +        if dp[i] != -1 and i + w <= W: +            dp[i + w] = max(dp[i] + v, dp[i + w]) +print((max(dp)))