#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
vector<long long> prime;
bitset<1000030> vis;
void seive() {
  vis.set();
  vis[0] = false;
  vis[1] = false;
  vis[2] = true;
  prime.push_back(2);
  for (long long i = 3; i <= 1000030; i += 2) {
    if (vis[i] == 1) {
      prime.push_back(i);
      for (long long j = i * i; j <= 1000030; j += i) {
        vis[j] = 0;
      }
    }
  }
}
bool isPrime(long long n) {
  if (n < 2) return false;
  if (n < 4) return true;
  if (!(n & 1)) return false;
  if (n % 3 == 0) return false;
  long long lim = sqrt(n);
  for (long long i = 5; i <= lim; i += 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
map<long long, long long> primeFact(long long n) {
  map<long long, long long> make_pair;
  while (n % 2 == 0) {
    make_pair[2]++;
    n = n / 2;
  }
  for (long long i = 3; i <= sqrt(n); i += 2) {
    while (n % i == 0) {
      make_pair[i]++;
      n = n / i;
    }
  }
  if (n > 2) {
    make_pair[n]++;
  }
  return make_pair;
}
long long binomialCoeff(long long n, long long k) {
  if (k > n) return 0;
  long long C[n + 1][k + 1];
  long long i, j;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= min(i, k); j++) {
      if (j == 0 || j == i)
        C[i][j] = 1;
      else
        C[i][j] =
            (C[i - 1][j - 1] % (1000000007) + C[i - 1][j] % (1000000007)) %
            (1000000007);
    }
  }
  return C[n][k];
}
long long countDivisors(long long n) {
  long long cnt = 0;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else {
        cnt += 2;
      }
    }
  }
  return cnt;
}
long long reverse_number(long long n) {
  long long rev = 0, r;
  while (n != 0) {
    r = n % 10;
    rev = rev * 10 + r;
    n /= 10;
  }
  return rev;
}
long long cnt[100005];
void solve() {
  long long a, b;
  cin >> a >> b;
  vector<long long> v1(6, 0), v2(6, 0);
  map<long long, long long> m1 = primeFact(a), m2 = primeFact(b);
  long long p1 = 1, p2 = 1;
  for (auto p : m1) {
    if (p.first == 2 || p.first == 5 || p.first == 3) {
      p1 *= pow(p.first, p.second);
      v1[p.first] = p.second;
    }
  }
  for (auto p : m2) {
    if (p.first == 2 || p.first == 5 || p.first == 3) {
      p2 *= pow(p.first, p.second);
      v2[p.first] = p.second;
    }
  }
  if (a / p1 != b / p2) {
    cout << "-1"
         << "\n";
    return;
  }
  cout << abs(v1[2] - v2[2]) + abs(v1[3] - v2[3]) + abs(v1[5] - v2[5]) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
