# 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()))



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

dp[0]=0



for _ in range(N):

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

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

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

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



print((max(dp)))    
# 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()))
dp = [-1] * (W + 1)
dp[0] = 0
for _ in range(N):
    w, v = list(map(int, input().split()))
    for i in range(W + 1)[::-1]:
        if dp[i] != -1 and i + w <= W:
            dp[i + w] = max(dp[i + w], dp[i] + v)
print((max(dp)))

-jwels = [] -for _ in range(N): -    jwels.append(list(map(int, input().split()))) -for w, v in jwels: +for _ in range(N): +    w, v = list(map(int, input().split())) -            dp[i + w] = max(dp[i] + v, dp[i + w]) +            dp[i + w] = max(dp[i + w], dp[i] + v)