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

Weight = [0]

Value = [0]

ans = 0

for i in range(N):

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

    Weight.append(w)

    Value.append(v)

VS = sum(Value)

DP = [[float('inf')] * (VS + 1) for i in range(N + 1)]



for n in range(N + 1):

    for val in range(VS + 1):

        if val == 0:

            DP[n][val] = 0

        elif Value[n] > val:

            DP[n][val] = DP[n - 1][val]

        else:

            DP[n][val] = min(DP[n - 1][val], DP[n - 1][val - Value[n]] + Weight[n])

            if (n == N) and (DP[n][val] <= W):

                ans = max(ans, val)



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

Items = [tuple(map(int, input().split())) for _ in range(N)]

DP = [float('inf')] * 10 ** 6

DP[0] = 0

for w, v in Items:

    D = DP[:]

    for i, d in enumerate(DP):

        if w + d > W:

            continue

        D[i + v] = min(DP[i + v], w + d)

    DP = D

ans = 0

for i, d in enumerate(DP):

    if d == float('inf'):

        continue

    ans = i

print(ans)
N, W = list(map(int, input().split()))
Weight = [0]
Value = [0]
ans = 0
for i in range(N):
    w, v = list(map(int, input().split()))
    Weight.append(w)
    Value.append(v)
VS = sum(Value)
DP = [[float("inf")] * (VS + 1) for i in range(N + 1)]
for n in range(N + 1):
    for val in range(VS + 1):
        if val == 0:
            DP[n][val] = 0
        elif Value[n] > val:
            DP[n][val] = DP[n - 1][val]
        else:
            DP[n][val] = min(DP[n - 1][val], DP[n - 1][val - Value[n]] + Weight[n])
            if (n == N) and (DP[n][val] <= W):
                ans = max(ans, val)
print(ans)

N, W = list(map(int, input().split()))
Items = [tuple(map(int, input().split())) for _ in range(N)]
DP = [float("inf")] * 10**6
DP[0] = 0
for w, v in Items:
    D = DP[:]
    for i, d in enumerate(DP):
        if w + d > W:
            continue
        D[i + v] = min(DP[i + v], w + d)
    DP = D
ans = 0
for i, d in enumerate(DP):
    if d == float("inf"):
        continue
    ans = i
print(ans)

-Weight = [0] -Value = [0] +Items = [tuple(map(int, input().split())) for _ in range(N)] +DP = [float("inf")] * 10**6 +DP[0] = 0 +for w, v in Items: +    D = DP[:] +    for i, d in enumerate(DP): +        if w + d > W: +            continue +        D[i + v] = min(DP[i + v], w + d) +    DP = D -for i in range(N): -    w, v = list(map(int, input().split())) -    Weight.append(w) -    Value.append(v) -VS = sum(Value) -DP = [[float("inf")] * (VS + 1) for i in range(N + 1)] -for n in range(N + 1): -    for val in range(VS + 1): -        if val == 0: -            DP[n][val] = 0 -        elif Value[n] > val: -            DP[n][val] = DP[n - 1][val] -        else: -            DP[n][val] = min(DP[n - 1][val], DP[n - 1][val - Value[n]] + Weight[n]) -            if (n == N) and (DP[n][val] <= W): -                ans = max(ans, val) +for i, d in enumerate(DP): +    if d == float("inf"): +        continue +    ans = i