#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline void ckmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void ckmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
long long gcd(long long a, long long b) {
  while (b) {
    long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  long long limit;
  while (cin >> n >> limit) {
    char s[32];
    vector<long long> a(n);
    vector<int> e(n);
    for (int i = 0; i < (n); ++i) {
      cin >> s;
      a[i] = atoll(s);
    }
    for (int i = 0; i < (n); ++i) cin >> e[i];
    long long d = 0;
    for (int i = 0; i < (n); ++i) d = gcd(d, a[i]);
    vector<int> sorted_by_e(n);
    for (int i = 0; i < (n); ++i) sorted_by_e[i] = i;
    sort(sorted_by_e.begin(), sorted_by_e.end(),
         [&](int a, int b) { return e[a] < e[b]; });
    vector<long long> c;
    for (long long m = 2; d > 1;) {
      if (d % m == 0) {
        c.push_back(m);
        for (; d % m == 0; d /= m)
          ;
      }
      m++;
      if (m * m > d) m = d;
    }
    for (int i = 0; i < (n); ++i) {
      long long t = a[i];
      for (long long x : c)
        for (; t % x == 0; t /= x)
          ;
      a[i] = a[i] / t;
    }
    int length = ((int)c.size());
    unordered_map<long long, int> visited;
    vector<pair<int, long long>> h;
    h.reserve(n);
    for (int cl = 0; cl < (n); ++cl) {
      int i = sorted_by_e[cl];
      if (visited[a[i]] > length) continue;
      ++visited[a[i]];
      h.emplace_back(e[i], a[i]);
    }
    vector<vector<long long>> f(1 << length);
    for (int set = 0; set < ((1 << length)); ++set)
      f[set].resize(length + 1, (1LL << 60));
    f[0][0] = 0;
    vector<long long> g0(1 << length);
    vector<int> g1(1 << length);
    for (int set = (1); set < ((1 << length)); ++set)
      for (int i = 0; i < (length); ++i)
        if (set & (1 << i)) g1[set] = i;
    vector<int> vcnt(1 << length);
    for (const auto &w : h) {
      vector<long long> z(length);
      for (int i = 0; i < (length); ++i) z[i] = 1;
      for (int i = 0; i < (length); ++i) {
        long long t = w.second;
        for (; t % c[i] == 0; t /= c[i]) z[i] *= c[i];
      }
      g0[0] = 1;
      for (int set = (1); set < ((1 << length)); ++set)
        g0[set] = g0[set ^ (1 << g1[set])] * z[g1[set]];
      int ok = 0;
      for (int set = (1); set < ((1 << length)); ++set)
        if (g0[set] <= limit)
          if (vcnt[set] < length)
            ok = 1, ++vcnt[set];
          else
            g0[set] = limit + 1;
      if (!ok) continue;
      for (int set = (1 << length) - 1; set > 0; set--)
        for (int subset = set; subset > 0; subset = (subset - 1) & set)
          if (g0[subset] <= limit)
            for (int i = 1; i <= length; i++) {
              ckmin(f[set][i], f[set ^ subset][i - 1] + w.first);
            }
    }
    long long ret = (1LL << 60);
    for (int i = 0; i < (length + 1); ++i) {
      long long t = f[(1 << length) - 1][i];
      if (t >= (1LL << 60)) continue;
      ckmin(ret, i * t);
    }
    if (ret >= (1LL << 60)) ret = -1;
    cout << ret << endl;
    break;
  }
  return 0;
}
