#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e6 + 1e2;
long long val[maxn], num[maxn];
long long prime[maxn];
long long n, m, tot, k;
pair<long long, long long> b[maxn];
unordered_map<long long, long long> used;
long long cost[maxn];
int ci[maxn];
long long f[14][4010];
long long g[14][4010];
long long ptx[maxn];
long long cnt[maxn];
long long lim;
long long lowbit(long long x) { return x & (-x); }
long long gcd(long long a, long long b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
signed main() {
  n = read(), lim = read();
  for (int i = 1; i <= n; i++) num[i] = read();
  long long gc = num[1];
  for (int i = 2; i <= n; i++) gc = gcd(gc, num[i]);
  if (gc == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) val[i] = read();
  long long now = gc;
  for (long long i = 2; i * i <= gc; i++) {
    if (now % i == 0) {
      prime[++m] = i;
      while (now % i == 0) now /= i, ci[m]++;
    }
  }
  if (now > 1) prime[++m] = now, ci[m] = 1;
  for (int i = 1; i <= n; i++) {
    long long now = 1;
    for (int j = 1; j <= m; j++)
      while (num[i] % prime[j] == 0) now *= prime[j], num[i] /= prime[j];
    b[++tot] = make_pair(val[i], now);
  }
  sort(b + 1, b + 1 + n);
  memset(f, 127 / 3, sizeof(f));
  f[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    bool flag = 0;
    if (used[b[i].second] > m) continue;
    used[b[i].second]++;
    cost[0] = 1;
    ptx[0] = 1;
    long long ymh = b[i].second;
    for (int j = 1; j <= m; j++) {
      cost[1 << j - 1] = 1;
      while (ymh % prime[j] == 0) {
        cost[1 << j - 1] *= prime[j];
        ymh /= prime[j];
      }
    }
    memcpy(g, f, sizeof(g));
    for (int j = 0; j < (1 << m); j++) {
      ptx[j] = ptx[j ^ lowbit(j)] * cost[lowbit(j)];
      long long now = ((1 << m) - 1) ^ j;
      if (ptx[j] > lim) continue;
      for (int k = now; k; k = (k - 1) & now) {
        for (int p = 1; p <= m; p++)
          if (g[p - 1][k] + b[i].first <= f[p][j | k])
            f[p][j | k] = g[p - 1][k] + b[i].first, flag = 1;
      }
      if (g[0][0] + b[i].first <= f[1][j])
        f[1][j] = g[0][0] + b[i].first, flag = 1;
    }
  }
  long long ans = 1e18;
  for (long long i = 1; i <= m; i++)
    if (f[i][(1 << m) - 1] != f[13][4002])
      ans = min(ans, f[i][(1 << m) - 1] * i);
  if (ans == 1e18) ans = -1;
  cout << ans << endl;
  return 0;
}
