#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
map<long long, long long> ma;
void pf(long long n) {
  while (n % 2 == 0) {
    ma[2]++;
    n = n / 2;
  }
  for (unsigned long long int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      ma[i]++;
      n = n / i;
    }
  }
  if (n > 2) ma[n]++;
}
int main() {
  long long a, b;
  cin >> a >> b;
  if (a == b)
    cout << "0";
  else {
    long long r = gcd(a, b);
    long long k = a / r;
    long long c = b / r;
    pf(k);
    pf(c);
    map<long long, long long>::iterator it;
    long long count = 0;
    for (it = ma.begin(); it != ma.end(); it++) {
      if (it->first != 2 && it->first != 5 && it->first != 3) {
        cout << "-1";
        return 0;
      }
      count += (it->second);
    }
    cout << count;
  }
}
