from itertools import accumulate

n,W,*L=list(map(int,open(0).read().split()))

l=[[] for _ in range(4)]

lim=[1]*4

m=min(L[::2])

for w,v in zip(*[iter(L)]*2):

	l[w-m].append(v)

	lim[w-m]+=1

ll=[]

for x in l:

	ll.append([0]+list(accumulate(sorted(x)[::-1])))

ans=0

for i in range(lim[0]):

	for j in range(lim[1]):

		for k in range(lim[2]):

			for l in range(lim[3]):

				if m*i+(m+1)*j+(m+2)*k+(m+3)*l>W:

					continue

				ans=max(ans,ll[0][i]+ll[1][j]+ll[2][k]+ll[3][l])

print(ans)
from itertools import accumulate

n,W,*L=list(map(int,open(0).read().split()))

l=[[] for _ in range(4)]

lim=[1]*4

m=min(L[::2])

for w,v in zip(*[iter(L)]*2):

	l[w-m].append(v)

	lim[w-m]+=1

ll=[]

for x in l:

	ll.append([0]+list(accumulate(sorted(x)[::-1])))

ans=0

for i in range(lim[0]):

	if m*i>W:

		continue

	for j in range(lim[1]):

		if m*i+(m+1)*j>W:

			continue

		for k in range(lim[2]):

			if m*i+(m+1)*j+(m+2)*k>W:

				continue

			for l in range(lim[3]):

				if m*i+(m+1)*j+(m+2)*k+(m+3)*l>W:

					continue

				ans=max(ans,ll[0][i]+ll[1][j]+ll[2][k]+ll[3][l])

print(ans)
from itertools import accumulate

n, W, *L = list(map(int, open(0).read().split()))
l = [[] for _ in range(4)]
lim = [1] * 4
m = min(L[::2])
for w, v in zip(*[iter(L)] * 2):
    l[w - m].append(v)
    lim[w - m] += 1
ll = []
for x in l:
    ll.append([0] + list(accumulate(sorted(x)[::-1])))
ans = 0
for i in range(lim[0]):
    for j in range(lim[1]):
        for k in range(lim[2]):
            for l in range(lim[3]):
                if m * i + (m + 1) * j + (m + 2) * k + (m + 3) * l > W:
                    continue
                ans = max(ans, ll[0][i] + ll[1][j] + ll[2][k] + ll[3][l])
print(ans)

from itertools import accumulate

n, W, *L = list(map(int, open(0).read().split()))
l = [[] for _ in range(4)]
lim = [1] * 4
m = min(L[::2])
for w, v in zip(*[iter(L)] * 2):
    l[w - m].append(v)
    lim[w - m] += 1
ll = []
for x in l:
    ll.append([0] + list(accumulate(sorted(x)[::-1])))
ans = 0
for i in range(lim[0]):
    if m * i > W:
        continue
    for j in range(lim[1]):
        if m * i + (m + 1) * j > W:
            continue
        for k in range(lim[2]):
            if m * i + (m + 1) * j + (m + 2) * k > W:
                continue
            for l in range(lim[3]):
                if m * i + (m + 1) * j + (m + 2) * k + (m + 3) * l > W:
                    continue
                ans = max(ans, ll[0][i] + ll[1][j] + ll[2][k] + ll[3][l])
print(ans)

+    if m * i > W: +        continue +        if m * i + (m + 1) * j > W: +            continue +            if m * i + (m + 1) * j + (m + 2) * k > W: +                continue