#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 4e3 + 10;
int main() {
  int a, b;
  cin >> a >> b;
  function<int(int, int)> gcd = [&](int n, int m) -> int {
    return m == 0 ? n : gcd(m, n % m);
  };
  auto check = [](int x) -> int {
    int a[3] = {2, 3, 5};
    int cnt = 0;
    for (int i = 0; i < 3; i++)
      while (x % a[i] == 0) x /= a[i], cnt++;
    if (x != 1) cnt = -INF;
    return cnt;
  };
  int g = gcd(a, b);
  int ans = check(a / g) + check(b / g);
  if (ans < 0) ans = -1;
  cout << ans << endl;
  return 0;
}
