#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
void __print(long long int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void primeFactorization(long long int n, map<long long int, long long int> &m) {
  long long int ans = 1;
  while (n % 2 == 0) {
    m[2]++;
    n /= 2;
  }
  for (long long int i = 3; i * i <= n; i += 2) {
    while (n % i == 0) {
      m[i]++;
      n /= i;
    }
  }
  if (n > 2) {
    m[n]++;
  }
}
void solve() {
  long long int a, b;
  cin >> a >> b;
  map<long long int, long long int> ma, mb;
  primeFactorization(a, ma);
  primeFactorization(b, mb);
  long long int ans = 0;
  bool flag = true;
  ans += abs(ma[2] - mb[2]);
  ans += abs(ma[3] - mb[3]);
  ans += abs(ma[5] - mb[5]);
  for (auto it = ma.begin(); it != ma.end(); it++) {
    long long int num = it->first;
    if (num == 2 || num == 3 || num == 5) {
      continue;
    }
    if (mb[it->first] != it->second) {
      flag = false;
    }
  }
  for (auto it = mb.begin(); it != mb.end(); it++) {
    long long int num = it->first;
    if (num == 2 || num == 3 || num == 5) {
      continue;
    }
    if (ma[it->first] != it->second) {
      flag = false;
    }
  };
  if (flag) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
