#include <bits/stdc++.h>
using namespace std;
long long x, y;
map<long long, long long> m1, m2;
vector<long long> xs;
void primeFactors(long long n, map<long long, long long> &m) {
  while (n % 2 == 0) {
    m[2]++;
    n = n / 2;
  }
  while (n % 3 == 0) {
    m[3]++;
    n = n / 3;
  }
  while (n % 5 == 0) {
    m[5]++;
    n = n / 5;
  }
  if (n > 2) {
    xs.push_back(n);
  }
}
int main() {
  cin >> x >> y;
  primeFactors(x, m1);
  primeFactors(y, m2);
  if (xs.size() == 1) {
    cout << -1;
    return 0;
  }
  if (xs.size() == 2 && xs[0] != xs[1]) {
    cout << -1;
    return 0;
  }
  for (auto it : m1) {
    if (m2.find(it.first) == m2.end()) {
      m2[it.first] = 0;
    }
  }
  for (auto it : m2) {
    if (m1.find(it.first) == m1.end()) {
      m1[it.first] = 0;
    }
  }
  long long cnt = 0;
  int f = 0;
  for (auto it : m2) {
    if (m1[it.first] != 0 && m2[it.first] != 0) {
      f = 1;
    }
    cnt += abs(m1[it.first] - m2[it.first]);
  }
  cout << cnt;
  return 0;
}
