n, w = [int(i) for i in input().split()]



sv = {}

for i in range(n):

    ww, vv = list(map(int, input().split()))

    if ww > w:

        continue

    added = {}

    for k, v in list(sv.items()):

        if (ww+k) <= w:

            added[ww+k] = vv+v

    for k, v in list(added.items()):

        sv[k] = max(v, sv.get(k, 0))



    sv[ww] = max(vv, sv.get(ww, 0))



print((max(sv.values())))
import numpy as np



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



s = np.zeros(ww+1, dtype=np.int64)

for i in range(n):

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

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



print((s[ww]))
n, w = [int(i) for i in input().split()]
sv = {}
for i in range(n):
    ww, vv = list(map(int, input().split()))
    if ww > w:
        continue
    added = {}
    for k, v in list(sv.items()):
        if (ww + k) <= w:
            added[ww + k] = vv + v
    for k, v in list(added.items()):
        sv[k] = max(v, sv.get(k, 0))
    sv[ww] = max(vv, sv.get(ww, 0))
print((max(sv.values())))

import numpy as np

n, ww = list(map(int, input().split()))
s = np.zeros(ww + 1, dtype=np.int64)
for i in range(n):
    w, v = list(map(int, input().split()))
    s[w:] = np.maximum(s[w:], s[:-w] + v)
print((s[ww]))

-n, w = [int(i) for i in input().split()] -sv = {} +import numpy as np + +n, ww = list(map(int, input().split())) +s = np.zeros(ww + 1, dtype=np.int64) -    ww, vv = list(map(int, input().split())) -    if ww > w: -        continue -    added = {} -    for k, v in list(sv.items()): -        if (ww + k) <= w: -            added[ww + k] = vv + v -    for k, v in list(added.items()): -        sv[k] = max(v, sv.get(k, 0)) -    sv[ww] = max(vv, sv.get(ww, 0)) -print((max(sv.values()))) +    w, v = list(map(int, input().split())) +    s[w:] = np.maximum(s[w:], s[:-w] + v) +print((s[ww]))