#d

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

w=[0]

v=[0]

for i in range(n):

    x,y=list(map(int,input().split()))

    w.append(x)

    v.append(y)



dp=[[0]*(W+1) for i in range(110)]



for i in range(1,n+1):

    for j in range(W+1):

        dp[i][j]=dp[i-1][j]#if文Falseのときの値に困らないように

        if j-w[i]>=0:

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

print((dp[n][W]))

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

x=[0]+[-1]*W



for i in range(n):

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



    for j in range(W-w,-1,-1):

        if x[j]>=0:

            x[j+w]=max(x[j+w],x[j]+v)



print((max(x)))
# d
n, W = list(map(int, input().split()))
w = [0]
v = [0]
for i in range(n):
    x, y = list(map(int, input().split()))
    w.append(x)
    v.append(y)
dp = [[0] * (W + 1) for i in range(110)]
for i in range(1, n + 1):
    for j in range(W + 1):
        dp[i][j] = dp[i - 1][j]  # if文Falseのときの値に困らないように
        if j - w[i] >= 0:
            dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i])
print((dp[n][W]))

n, W = list(map(int, input().split()))
x = [0] + [-1] * W
for i in range(n):
    w, v = list(map(int, input().split()))
    for j in range(W - w, -1, -1):
        if x[j] >= 0:
            x[j + w] = max(x[j + w], x[j] + v)
print((max(x)))

-# d -w = [0] -v = [0] +x = [0] + [-1] * W -    x, y = list(map(int, input().split())) -    w.append(x) -    v.append(y) -dp = [[0] * (W + 1) for i in range(110)] -for i in range(1, n + 1): -    for j in range(W + 1): -        dp[i][j] = dp[i - 1][j]  # if文Falseのときの値に困らないように -        if j - w[i] >= 0: -            dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]) -print((dp[n][W])) +    w, v = list(map(int, input().split())) +    for j in range(W - w, -1, -1): +        if x[j] >= 0: +            x[j + w] = max(x[j + w], x[j] + v) +print((max(x)))