#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, M = (1 << 11) + 10;
int n, cot, S;
long long ans, g, K, inf, dp[12][M], ys[12], xs[12];
pair<long long, long long> p[N];
map<long long, vector<long long>> ex;
vector<long long> cn;
bool vs[M];
char cp;
template <class T>
inline void rd(T &x) {
  cp = getchar();
  x = 0;
  for (; !isdigit(cp); cp = getchar())
    ;
  for (; isdigit(cp); cp = getchar()) x = x * 10 + (cp ^ 48);
}
inline long long gcd(long long x, long long y) {
  return (!y) ? x : gcd(y, x % y);
}
inline void dn(long long &x, long long y) {
  if (y < x) x = y;
}
int main() {
  int i, j;
  long long u, v;
  rd(n);
  rd(K);
  for (i = 0; i < n; ++i) rd(p[i].second);
  for (i = 0; i < n; ++i) rd(p[i].first);
  for (g = p[0].second, i = 1; i < n; ++i) g = gcd(g, p[i].second);
  if (g == 1LL) {
    puts("0");
    return 0;
  }
  sort(p, p + n);
  for (i = 2; (long long)i * i <= g; ++i)
    if (!(g % i)) {
      ys[cot++] = i;
      for (; !(g % i); g /= i)
        ;
    }
  if (g > 1) ys[cot++] = g;
  S = 1 << cot;
  if (ys[cot - 1] > K) {
    puts("-1");
    return 0;
  }
  for (i = 0; i < n; ++i) {
    u = p[i].second;
    for (j = 0; j < cot; ++j)
      for (v = ys[j]; !(u % v); u /= v)
        ;
    v = p[i].second / u;
    if (ex[v].size() < cot) ex[v].push_back(p[i].first);
  }
  memset(dp, 0x3f, sizeof(dp));
  inf = dp[0][0];
  dp[0][0] = 0LL;
  for (auto nw : ex) {
    u = nw.first;
    cn.clear();
    for (i = 0; i < cot; ++i) {
      xs[i] = 1;
      for (v = ys[i]; !(u % v); u /= v) xs[i] *= v;
    }
    memset(vs, false, sizeof(vs));
    for (i = S - 1; i; --i)
      if (!vs[i]) {
        for (u = 1LL, j = 0; j < cot; ++j)
          if ((i >> j) & 1) u *= xs[j];
        if (u <= K) {
          for (j = i; j; j = i & (j - 1)) vs[j] = true;
          cn.push_back(i);
        }
      }
    for (auto vl : nw.second) {
      for (i = cot - 1; ~i; --i)
        for (j = 0; j < S; ++j)
          if ((v = dp[i][j] + vl) < inf)
            for (int s : cn) dn(dp[i + 1][j | s], v);
    }
  }
  for (ans = inf, S--, i = 1; i <= cot; ++i)
    if (dp[i][S] < inf / i) dn(ans, dp[i][S] * i);
  if (ans == inf) ans = -1LL;
  printf("%I64d", ans);
  return 0;
}
