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



dp = [[-1] * (W + 1) for i in range(N + 1)]

dp[0][0] = 0



for i in range(N):

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

  for j in range(len(dp[i]) - 2, -1, -1):

    if dp[i][j] == -1:

      continue

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

    if j + w >= len(dp[i]):

      continue

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



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

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



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



for i in range(N):

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

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

  

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

import numpy as np

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

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