import sys

input = sys.stdin.readline  #文字列入力では注意！



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

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



for i in range(N):

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

    for j in range(W+1):

        if j+w <= W:

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

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



print((dp[N][W]))

import numpy as np

import sys

input = sys.stdin.readline  #文字列入力では注意！



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



dp = np.zeros(W+1, dtype=np.int64)

for i in range(N):

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

    np.maximum(dp[:-w]+v, dp[w:], out = dp[w:])



print((dp[-1]))

import sys

input = sys.stdin.readline  # 文字列入力では注意！
N, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
    w, v = list(map(int, input().split()))
    for j in range(W + 1):
        if j + w <= W:
            dp[i + 1][j + w] = dp[i][j] + v
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print((dp[N][W]))

import numpy as np
import sys

input = sys.stdin.readline  # 文字列入力では注意！
N, W = list(map(int, input().split()))
dp = np.zeros(W + 1, dtype=np.int64)
for i in range(N):
    w, v = list(map(int, input().split()))
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print((dp[-1]))

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