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

k=[[0,0] for i in range(N)]

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

for i in range(N):

    k[i][0],k[i][1]=list(map(int,input().split()))







for i in range(N):

    for w in range(W+1):

        if k[i][0]>w:

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

        else:

            dp[i+1][w] = max(dp[i][w-k[i][0]]+k[i][1],dp[i][w])





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



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

w, v = [], []

for i in range(N):

    a, b = list(map(int, input().split()))

    w += [a]

    v += [b]



DP = np.zeros(W + 1,dtype=int)



for i in range(N):

    # print(DP[w[i]:])

    # print(DP[:-w[i]])

    # print(DP[:-w[i]] + v[i])

    DP[w[i]:] = np.maximum(DP[:-w[i]] + v[i], DP[w[i]:])

    # print(DP)

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

import numpy as np

N, W = list(map(int, input().split()))
w, v = [], []
for i in range(N):
    a, b = list(map(int, input().split()))
    w += [a]
    v += [b]
DP = np.zeros(W + 1, dtype=int)
for i in range(N):
    # print(DP[w[i]:])
    # print(DP[:-w[i]])
    # print(DP[:-w[i]] + v[i])
    DP[w[i] :] = np.maximum(DP[: -w[i]] + v[i], DP[w[i] :])
    # print(DP)
print((DP[-1]))

+import numpy as np + -k = [[0, 0] for i in range(N)] -dp = [[0] * (W + 1) for j in range(N + 1)] +w, v = [], [] -    k[i][0], k[i][1] = list(map(int, input().split())) +    a, b = list(map(int, input().split())) +    w += [a] +    v += [b] +DP = np.zeros(W + 1, dtype=int) -    for w in range(W + 1): -        if k[i][0] > w: -            dp[i + 1][w] = dp[i][w] -        else: -            dp[i + 1][w] = max(dp[i][w - k[i][0]] + k[i][1], dp[i][w]) -print((dp[N][W])) +    # print(DP[w[i]:]) +    # print(DP[:-w[i]]) +    # print(DP[:-w[i]] + v[i]) +    DP[w[i] :] = np.maximum(DP[: -w[i]] + v[i], DP[w[i] :]) +    # print(DP) +print((DP[-1]))