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

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



dp[0][W] = 0

for i in range(n):

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

    for j in range(W + 1):

        if j >= w:

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

        else:

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

print((dp[n][W]))
import numpy as np

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

dp = np.zeros((n + 1, W + 1))



for i in range(n):

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

    dp[i + 1] = dp[i]

    if w <= W:

        dp[i + 1][w:] = np.maximum(dp[i][:W - w + 1] + v, dp[i][w:])

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

import numpy as np

n, W = list(map(int, input().split()))
dp = np.zeros((n + 1, W + 1))
for i in range(n):
    w, v = list(map(int, input().split()))
    dp[i + 1] = dp[i]
    if w <= W:
        dp[i + 1][w:] = np.maximum(dp[i][: W - w + 1] + v, dp[i][w:])
print((int(dp[n][W])))

+import numpy as np + -dp = [[0] * (W + 1) for _ in range(n + 1)] -dp[0][W] = 0 +dp = np.zeros((n + 1, W + 1)) -    for j in range(W + 1): -        if j >= w: -            dp[i + 1][j] = max(dp[i][j - w] + v, dp[i][j]) -        else: -            dp[i + 1][j] = dp[i][j] -print((dp[n][W])) +    dp[i + 1] = dp[i] +    if w <= W: +        dp[i + 1][w:] = np.maximum(dp[i][: W - w + 1] + v, dp[i][w:]) +print((int(dp[n][W])))