from collections import defaultdict 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) d = defaultdict() d[0] = 0 for i in range(n): if x[i] < w: continue tmp = d.copy() for k, v in tmp.items(): gcd = GCD(k, x[i]) if gcd >= w: tmp[gcd] = v + y[i] d[x[i]] = y[i] d.update(tmp) print(max(d.values()))