#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long gcd;
  if (a == 1)
    return 1;
  else if (b == 1)
    return 1;
  while (b) {
    long long t = b;
    b = a % b;
    a = t;
  }
  gcd = a;
  return gcd;
}
long long check(long long &n) {
  long long ck = 0;
  for (long long i = 2;;) {
    if (n % i == 0) {
      n /= i;
      ck++;
    } else
      break;
  }
  for (long long i = 3;;) {
    if (n % i == 0) {
      n /= i;
      ck++;
    } else
      break;
  }
  for (long long i = 5;;) {
    if (n % i == 0) {
      n /= i;
      ck++;
    } else
      break;
  }
  return ck;
}
int main() {
  long long a, b;
  cin >> a >> b;
  if (a == b) {
    cout << "0";
    return 0;
  }
  long long x = gcd(a, b);
  a /= x;
  b /= x;
  long long sum1, sum2;
  sum1 = check(a);
  sum2 = check(b);
  if (a == 1 && b == 1)
    cout << sum1 + sum2 << endl;
  else
    cout << "-1" << endl;
  return 0;
}
