import sys readline=sys.stdin.readline N,C=map(int,readline().split()) L=list(map(int,readline().split())) W=list(map(int,readline().split())) inf=1<<10 max_L=max(L) dp=[[-inf]*(N**2) for c in range(C+1)] for i in range(N): for j in range(N): for k in range(N): if W[i]+W[j]+W[k]<=C and L[i]!=L[k] and (L[i]-L[j])*(L[k]-L[j])>0: dp[W[i]+W[j]+W[k]][j*N+k]=L[i]+L[j]+L[k] for c in range(C+1): for i in range(N): for j in range(N): for k in range(N): if L[i]!=L[k] and (L[i]-L[j])*(L[k]-L[j])>0 and c+W[k]<=C: dp[c+W[k]][j*N+k]=max(dp[c+W[k]][j*N+k],dp[c][i*N+j]+L[k]) ans=max(max(dp[c]) for c in range(C+1)) if ans<0: ans=0 print(ans)