n, w = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) def GCD(a, b): while b != 0: tmp = b b = a % b a = tmp return a rng = max(x) - w if rng < 0: print(0) exit(0) stack = set() stack.add((0,0)) for i in range(n): if x[i] < w: continue tmp = set() for elm in stack: gcd = GCD(elm[0], x[i]) if gcd >= w: tmp.add((gcd,elm[1]+y[i])) stack.add((x[i],y[i])) stack|=tmp print(max(stack, key=lambda x: x[1])[1])