import numpy as np



n,W = (int(i) for i in input().split())

weights = []

values = []

for j in range(n):

    wt, val = [int(i) for i in input().split()]

    weights.append(wt)

    values.append(val)



dp  = np.zeros(W+1)



for i in range(1,n+1):

    w = weights[i-1]

    v = values[i-1]

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



print((int(dp[-1])))

import numpy as np



n,W = (int(i) for i in input().split())

items=[[int(i) for i in input().split()]for j in range(n)]



dp  = np.zeros(W+1)



for w,v in items:

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



print((int(dp[-1])))

import numpy as np

n, W = (int(i) for i in input().split())
weights = []
values = []
for j in range(n):
    wt, val = [int(i) for i in input().split()]
    weights.append(wt)
    values.append(val)
dp = np.zeros(W + 1)
for i in range(1, n + 1):
    w = weights[i - 1]
    v = values[i - 1]
    dp[w:] = np.maximum(dp[w:], v + dp[:-w])
print((int(dp[-1])))

import numpy as np

n, W = (int(i) for i in input().split())
items = [[int(i) for i in input().split()] for j in range(n)]
dp = np.zeros(W + 1)
for w, v in items:
    dp[w:] = np.maximum(dp[w:], v + dp[:-w])
print((int(dp[-1])))

-weights = [] -values = [] -for j in range(n): -    wt, val = [int(i) for i in input().split()] -    weights.append(wt) -    values.append(val) +items = [[int(i) for i in input().split()] for j in range(n)] -for i in range(1, n + 1): -    w = weights[i - 1] -    v = values[i - 1] +for w, v in items: