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

w_ls, v_ls = [0] * n, [0] * n

for i in range(n):

    w_ls[i], v_ls[i] = list(map(int,input().split()))

V = sum(v_ls)

dp = [[float("inf")] * (V+1) for _ in range(n+1)]

dp[0][0] = 0

for i in range(n):

    for j in range(V+1):

        if j - v_ls[i] >= 0:

            dp[i+1][j] = min(dp[i+1][j], dp[i][j-v_ls[i]] + w_ls[i])

        dp[i+1][j] = min(dp[i+1][j], dp[i][j])



ans = 0

for j in range(V+1):

    if dp[n][j] <= w:

        ans = j



print(ans)
n,w_limit = list(map(int,input().split()))



item_ls = [[0,0]]

total_value = 0

for i in range(n):

    cost, value = list(map(int,input().split()))

    item_ls.append([cost, value])

    total_value += value





dp = [[float('inf')] * (total_value+1) for _ in range(n+1)]

dp[0][0] = 0

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

    item_cost, item_value = item_ls[i]

    for sum_value in range(0,total_value+1):

        if sum_value-item_value >= 0:

            dp[i][sum_value] = min(dp[i][sum_value], dp[i-1][sum_value-item_value] + item_cost)

        dp[i][sum_value] = min(dp[i][sum_value], dp[i-1][sum_value])



ans = 0

for value, cost in enumerate(dp[n]):

    if cost <= w_limit:

        ans = max(ans, value)

print(ans)

n, w = list(map(int, input().split()))
w_ls, v_ls = [0] * n, [0] * n
for i in range(n):
    w_ls[i], v_ls[i] = list(map(int, input().split()))
V = sum(v_ls)
dp = [[float("inf")] * (V + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
    for j in range(V + 1):
        if j - v_ls[i] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v_ls[i]] + w_ls[i])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
ans = 0
for j in range(V + 1):
    if dp[n][j] <= w:
        ans = j
print(ans)

n, w_limit = list(map(int, input().split()))
item_ls = [[0, 0]]
total_value = 0
for i in range(n):
    cost, value = list(map(int, input().split()))
    item_ls.append([cost, value])
    total_value += value
dp = [[float("inf")] * (total_value + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(1, n + 1):
    item_cost, item_value = item_ls[i]
    for sum_value in range(0, total_value + 1):
        if sum_value - item_value >= 0:
            dp[i][sum_value] = min(
                dp[i][sum_value], dp[i - 1][sum_value - item_value] + item_cost
            )
        dp[i][sum_value] = min(dp[i][sum_value], dp[i - 1][sum_value])
ans = 0
for value, cost in enumerate(dp[n]):
    if cost <= w_limit:
        ans = max(ans, value)
print(ans)

-n, w = list(map(int, input().split())) -w_ls, v_ls = [0] * n, [0] * n +n, w_limit = list(map(int, input().split())) +item_ls = [[0, 0]] +total_value = 0 -    w_ls[i], v_ls[i] = list(map(int, input().split())) -V = sum(v_ls) -dp = [[float("inf")] * (V + 1) for _ in range(n + 1)] +    cost, value = list(map(int, input().split())) +    item_ls.append([cost, value]) +    total_value += value +dp = [[float("inf")] * (total_value + 1) for _ in range(n + 1)] -for i in range(n): -    for j in range(V + 1): -        if j - v_ls[i] >= 0: -            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v_ls[i]] + w_ls[i]) -        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]) +for i in range(1, n + 1): +    item_cost, item_value = item_ls[i] +    for sum_value in range(0, total_value + 1): +        if sum_value - item_value >= 0: +            dp[i][sum_value] = min( +                dp[i][sum_value], dp[i - 1][sum_value - item_value] + item_cost +            ) +        dp[i][sum_value] = min(dp[i][sum_value], dp[i - 1][sum_value]) -for j in range(V + 1): -    if dp[n][j] <= w: -        ans = j +for value, cost in enumerate(dp[n]): +    if cost <= w_limit: +        ans = max(ans, value)