#include <bits/stdc++.h>
using namespace std;
unsigned int gcd(unsigned int a, unsigned int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  unsigned int a, b;
  cin >> a >> b;
  unsigned int g = gcd(a, b);
  unsigned int ra = a / g, rb = b / g;
  unsigned int r = 0;
  while (ra % 2 == 0) ra /= 2, ++r;
  while (ra % 3 == 0) ra /= 3, ++r;
  while (ra % 5 == 0) ra /= 5, ++r;
  while (rb % 2 == 0) rb /= 2, ++r;
  while (rb % 3 == 0) rb /= 3, ++r;
  while (rb % 5 == 0) rb /= 5, ++r;
  bool ok = ra == 1 && rb == 1;
  if (ok)
    cout << r << endl;
  else
    cout << -1 << endl;
  return 0;
}
