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

dp = [0]*(W+1)

for _ in range(N):

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

    if w > W:

        continue

    else:

        for j in range(w,W+1)[::-1]:

            if dp[j] < dp[j-w]+v:

                dp[j] = dp[j-w]+v

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

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

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

for _ in range(N):

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

    if w > W:

        continue

    else:

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

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

import numpy as np

N, W = list(map(int, input().split()))
dp = np.zeros(W + 1, dtype=np.int64)
for _ in range(N):
    w, v = list(map(int, input().split()))
    if w > W:
        continue
    else:
        np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])
print((dp[W]))

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