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

w = [[] for i in range(4)]

w1,v1 = list(map(int,input().split()))

w[0].append(v1)

for i in range(N-1):

    wi,vi = list(map(int,input().split()))

    w[wi-w1].append(vi)

num = []

for i in range(4):

    w[i].sort(reverse= 1)

    num.append(len(w[i]))

ans = 0

for n1 in range(num[0]+1):

    for n2 in range(num[1]+1):

        for n3 in range(num[2]+1):

            for n4 in range(num[3]+1):

                wc = w1*(n1+n2+n3+n4) + n2 + 2*n3 + 3*n4

                if wc <= W:

                    vc = sum(w[0][:n1])+sum(w[1][:n2])+sum(w[2][:n3])+sum(w[3][:n4])

                    ans = max(ans,vc)

print(ans)

        
from itertools import accumulate

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

w = [[] for i in range(4)]

w1,v1 = list(map(int,input().split()))

w[0].append(v1)

for i in range(N-1):

    wi,vi = list(map(int,input().split()))

    w[wi-w1].append(vi)

num = []

for i in range(4):

    w[i].sort(reverse= 1)

    w[i] = [0]+list(accumulate(w[i]))

    num.append(len(w[i]))

ans = 0

for n1 in range(num[0]):

    for n2 in range(num[1]):

        for n3 in range(num[2]):

            for n4 in range(num[3]):

                wc = w1*(n1+n2+n3+n4) + n2 + 2*n3 + 3*n4

                if wc <= W:

                    vc = w[0][n1]+w[1][n2]+w[2][n3]+w[3][n4]

                    ans = max(ans,vc)

print(ans)

        
N, W = list(map(int, input().split()))
w = [[] for i in range(4)]
w1, v1 = list(map(int, input().split()))
w[0].append(v1)
for i in range(N - 1):
    wi, vi = list(map(int, input().split()))
    w[wi - w1].append(vi)
num = []
for i in range(4):
    w[i].sort(reverse=1)
    num.append(len(w[i]))
ans = 0
for n1 in range(num[0] + 1):
    for n2 in range(num[1] + 1):
        for n3 in range(num[2] + 1):
            for n4 in range(num[3] + 1):
                wc = w1 * (n1 + n2 + n3 + n4) + n2 + 2 * n3 + 3 * n4
                if wc <= W:
                    vc = (
                        sum(w[0][:n1])
                        + sum(w[1][:n2])
                        + sum(w[2][:n3])
                        + sum(w[3][:n4])
                    )
                    ans = max(ans, vc)
print(ans)

from itertools import accumulate

N, W = list(map(int, input().split()))
w = [[] for i in range(4)]
w1, v1 = list(map(int, input().split()))
w[0].append(v1)
for i in range(N - 1):
    wi, vi = list(map(int, input().split()))
    w[wi - w1].append(vi)
num = []
for i in range(4):
    w[i].sort(reverse=1)
    w[i] = [0] + list(accumulate(w[i]))
    num.append(len(w[i]))
ans = 0
for n1 in range(num[0]):
    for n2 in range(num[1]):
        for n3 in range(num[2]):
            for n4 in range(num[3]):
                wc = w1 * (n1 + n2 + n3 + n4) + n2 + 2 * n3 + 3 * n4
                if wc <= W:
                    vc = w[0][n1] + w[1][n2] + w[2][n3] + w[3][n4]
                    ans = max(ans, vc)
print(ans)

+from itertools import accumulate + +    w[i] = [0] + list(accumulate(w[i])) -for n1 in range(num[0] + 1): -    for n2 in range(num[1] + 1): -        for n3 in range(num[2] + 1): -            for n4 in range(num[3] + 1): +for n1 in range(num[0]): +    for n2 in range(num[1]): +        for n3 in range(num[2]): +            for n4 in range(num[3]): -                    vc = ( -                        sum(w[0][:n1]) -                        + sum(w[1][:n2]) -                        + sum(w[2][:n3]) -                        + sum(w[3][:n4]) -                    ) +                    vc = w[0][n1] + w[1][n2] + w[2][n3] + w[3][n4]