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



items = [list(map(int,input().split())) for i in range(n)]



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



for i in range(n):

    for j in range(w+1):

        if j >= items[i][0]:

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

            

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



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



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

l = [list(map(int,input().split())) for i in range(n)]





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



for i in range(n):

    tmp = np.zeros(w + 1, dtype=int)

    tmp[l[i][0]:] = dp[i][:-l[i][0]] + l[i][1]

    dp[i + 1] = np.maximum(dp[i], tmp)

    

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

import numpy as np

n, w = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
dp = np.zeros((n + 1, w + 1), dtype=np.int64)
for i in range(n):
    tmp = np.zeros(w + 1, dtype=int)
    tmp[l[i][0] :] = dp[i][: -l[i][0]] + l[i][1]
    dp[i + 1] = np.maximum(dp[i], tmp)
print((dp[n][w]))

+import numpy as np + -items = [list(map(int, input().split())) for i in range(n)] -dp = [[0] * (w + 1) for i in range(n + 1)] +l = [list(map(int, input().split())) for i in range(n)] +dp = np.zeros((n + 1, w + 1), dtype=np.int64) -    for j in range(w + 1): -        if j >= items[i][0]: -            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - items[i][0]] + items[i][1]) -        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) +    tmp = np.zeros(w + 1, dtype=int) +    tmp[l[i][0] :] = dp[i][: -l[i][0]] + l[i][1] +    dp[i + 1] = np.maximum(dp[i], tmp)