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

from functools import lru_cache
@lru_cache(maxsize=None)
def calc(a,b,cost):
    ANS=0
    if a==b==0:
        for i in range(N):
            if W[i]<=cost:
                ANS=max(ANS,L[i]+calc(0,L[i],cost-W[i]))

        return ANS

    if a==0:
        for i in range(N):
            if L[i]!=b and W[i]<=cost:
                ANS=max(ANS,L[i]+calc(b,L[i],cost-W[i]))

        return ANS

    if a<b:
        for i in range(N):
            if W[i]<=cost and L[i]<b and L[i]!=a:
                ANS=max(ANS,L[i]+calc(b,L[i],cost-W[i]))
        return ANS
    else:
        for i in range(N):
            if W[i]<=cost and L[i]>b and L[i]!=a:
                ANS=max(ANS,L[i]+calc(b,L[i],cost-W[i]))
        return ANS

if len(set(sorted(L)))<=2:
    print(0)
else:
    ANS=0

    for i in range(N):
        for j in range(N):
            for k in range(N):
                if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i] and W[i]+W[j]+W[k]<=C:
                    if L[i]<L[j] and L[j]>L[k]:
                        ANS=max(ANS,L[i]+L[j]+L[k]+calc(L[j],L[k],C-W[i]-W[j]-W[k]))
                        
                    if L[i]>L[j] and L[j]<L[k]:
                        ANS=max(ANS,L[i]+L[j]+L[k]+calc(L[j],L[k],C-W[i]-W[j]-W[k]))

    print(ANS)