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

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





# 1~i-1番目の品物から重さの総和がj以下になるように選んだときの価値

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



for i in range(N):

    w, v = w_v[i]

    for j in range(W+1):

        if j - w >= 0:

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

        else:

            dp[i+1][j] = dp[i][j]



print((max(dp[N])))







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

data = []

for _ in range(n):

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

    data.append((w, v))



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



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

    w, v = data[i-1]

    for j in range(W+1):                

        if j - w >= 0:

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

        else:

            dp[i][j] = dp[i - 1][j]



print((dp[-1][W]))

N, W = list(map(int, input().split()))
w_v = [list(map(int, input().split())) for _ in range(N)]
# 1~i-1番目の品物から重さの総和がj以下になるように選んだときの価値
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
for i in range(N):
    w, v = w_v[i]
    for j in range(W + 1):
        if j - w >= 0:
            dp[i + 1][j] = max(dp[i][j - w] + v, dp[i][j])
        else:
            dp[i + 1][j] = dp[i][j]
print((max(dp[N])))

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

-N, W = list(map(int, input().split())) -w_v = [list(map(int, input().split())) for _ in range(N)] -# 1~i-1番目の品物から重さの総和がj以下になるように選んだときの価値 -dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)] -for i in range(N): -    w, v = w_v[i] +n, W = list(map(int, input().split())) +data = [] +for _ in range(n): +    w, v = list(map(int, input().split())) +    data.append((w, v)) +dp = [[0] * (W + 1) for i in range(n + 1)] +for i in range(1, n + 1): +    w, v = data[i - 1] -            dp[i + 1][j] = max(dp[i][j - w] + v, dp[i][j]) +            dp[i][j] = max(dp[i - 1][j - w] + v, dp[i - 1][j]) -            dp[i + 1][j] = dp[i][j] -print((max(dp[N]))) +            dp[i][j] = dp[i - 1][j] +print((dp[-1][W]))