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

dp = [-1]*(W+1)

dp[0] = 0

for _ in range(N):

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

    for i in range(W-w, -1, -1):

        if dp[i] == -1:

            continue

        if dp[i+w] < dp[i] + v:

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

print((max(dp)))
import numpy as np

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

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



for i in range(n):

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



    # print("left", dp[i, :w])

    # print("right", dp[i-1, :w])

    dp[i, :w] = dp[i-1, :w]

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



    # print(dp[i])

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

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

import numpy as np

n, W = list(map(int, input().split()))
dp = np.zeros((n, W + 1), dtype="int64")
for i in range(n):
    w, v = list(map(int, input().split()))
    # print("left", dp[i, :w])
    # print("right", dp[i-1, :w])
    dp[i, :w] = dp[i - 1, :w]
    dp[i, w:] = np.fmax(dp[i - 1, w:], dp[i - 1, : W - w + 1] + v)
    # print(dp[i])
print((dp[n - 1][W]))

-N, W = list(map(int, input().split())) -dp = [-1] * (W + 1) -dp[0] = 0 -for _ in range(N): +import numpy as np + +n, W = list(map(int, input().split())) +dp = np.zeros((n, W + 1), dtype="int64") +for i in range(n): -    for i in range(W - w, -1, -1): -        if dp[i] == -1: -            continue -        if dp[i + w] < dp[i] + v: -            dp[i + w] = dp[i] + v -print((max(dp))) +    # print("left", dp[i, :w]) +    # print("right", dp[i-1, :w]) +    dp[i, :w] = dp[i - 1, :w] +    dp[i, w:] = np.fmax(dp[i - 1, w:], dp[i - 1, : W - w + 1] + v) +    # print(dp[i]) +print((dp[n - 1][W]))