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

w = [0 for _ in range(N)]

v = [0 for _ in range(N)]

for i in range(N):

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

# print(w)

# print(v)

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

# print(dp)

# dp loop

for i in range(N):

    for sum_w in range(W+1):

        if sum_w - w[i] >= 0:

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

        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])

# print(dp)

print((dp[N][W]))
MAX_N = 110

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

weight = [0] * MAX_N

value = [0] * MAX_N

for i in range(N):

    weight[i], value[i] = list(map(int, input().split()))

dp = [[0] * (W + 1) for _ in range(MAX_N)]

for i in range(N):

    for sum_w in range(W + 1):

        if sum_w - weight[i] >= 0:

            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i])

        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])

# for l in dp:

#     print(l)

print((dp[N][W]))
N, W = list(map(int, input().split()))
w = [0 for _ in range(N)]
v = [0 for _ in range(N)]
for i in range(N):
    w[i], v[i] = list(map(int, input().split()))
# print(w)
# print(v)
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
# print(dp)
# dp loop
for i in range(N):
    for sum_w in range(W + 1):
        if sum_w - w[i] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
# print(dp)
print((dp[N][W]))

MAX_N = 110
N, W = list(map(int, input().split()))
weight = [0] * MAX_N
value = [0] * MAX_N
for i in range(N):
    weight[i], value[i] = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(MAX_N)]
for i in range(N):
    for sum_w in range(W + 1):
        if sum_w - weight[i] >= 0:
            dp[i + 1][sum_w] = max(
                dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]
            )
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
# for l in dp:
#     print(l)
print((dp[N][W]))

+MAX_N = 110 -w = [0 for _ in range(N)] -v = [0 for _ in range(N)] +weight = [0] * MAX_N +value = [0] * MAX_N -    w[i], v[i] = list(map(int, input().split())) -# print(w) -# print(v) -dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)] -# print(dp) -# dp loop +    weight[i], value[i] = list(map(int, input().split())) +dp = [[0] * (W + 1) for _ in range(MAX_N)] -        if sum_w - w[i] >= 0: -            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i]) +        if sum_w - weight[i] >= 0: +            dp[i + 1][sum_w] = max( +                dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i] +            ) -# print(dp) +# for l in dp: +#     print(l)