#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long gcd2(long long a, long long b, long long& x, long long& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = gcd2(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int mod = 1000000007;
inline int add(int a, int b) {
  int ret = a + b;
  if (ret >= mod) ret -= mod;
  return ret;
}
bool find_any_solution(long long a, long long b, long long c, long long& x0,
                       long long& y0, long long& g) {
  g = gcd2(abs(a), abs(b), x0, y0);
  if (c % g != 0) return false;
  x0 *= c / g;
  y0 *= c / g;
  if (a < 0) x0 *= -1;
  if (b < 0) y0 *= -1;
  return true;
}
void shift_solution(long long& x, long long& y, long long a, long long b,
                    long long cnt) {
  x += cnt * b;
  y -= cnt * a;
}
const double pi = 3.14159265358979323846;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, g, cnt = 0;
  cin >> a >> b;
  g = gcd(a, b);
  a /= g;
  b /= g;
  for (int p : {2, 3, 5}) {
    while (a % p == 0) {
      a /= p;
      cnt++;
    }
  }
  for (int p : {2, 3, 5}) {
    while (b % p == 0) {
      b /= p;
      cnt++;
    }
  }
  if (a != 1 || b != 1) cnt = -1;
  cout << cnt;
  return 0;
}
