N,C=map(int,input().split()) L=list(map(int,input().split())) W=list(map(int,input().split())) 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 ab 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: print(calc(0,0,C))