#include <bits/stdc++.h>
using namespace std;
int total_operation = 0;
bool is_prime(long long n) {
  if (n == 2) return true;
  if (n % 2 == 0 || n < 2) return false;
  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}
int countprime_in_range(int n) {
  vector<bool> isprime(n + 1, true);
  isprime[0] = isprime[1] = false;
  for (int i = 2; i * i <= n; ++i) {
    if (isprime[i]) {
      for (int j = 2 * i; j <= n; j += i) {
        isprime[j] = 0;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i <= n; i++) {
    if (isprime[i]) cnt++;
  }
  return cnt;
}
int main() {
  int fact1[3], fact2[3];
  fact1[0] = fact1[1] = fact1[2] = 0;
  fact2[0] = fact2[1] = fact2[2] = 0;
  int A, B;
  cin >> A >> B;
  if (A == B) {
    cout << "0";
    return 0;
  }
  while (A) {
    if (!(A % 2))
      fact1[0]++, A /= 2;
    else if (!(A % 3))
      fact1[1]++, A /= 3;
    else if (!(A % 5))
      fact1[2]++, A /= 5;
    else
      break;
  }
  while (B) {
    if (!(B % 2))
      fact2[0]++, B /= 2;
    else if (!(B % 3))
      fact2[1]++, B /= 3;
    else if (!(B % 5))
      fact2[2]++, B /= 5;
    else
      break;
  }
  if (A != B)
    cout << "-1";
  else
    cout << abs(fact1[0] - fact2[0]) + abs(fact1[1] - fact2[1]) +
                abs(fact1[2] - fact2[2]);
}
