#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6, MAX = 2e5 + 5, OO = 1000000009;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long x, long long y) { return (x * y / gcd(x, y)); }
long long fact(long long z) { return (z <= 1) ? 1 : z * fact(z - 1); }
int a, b, aa, bb, ans;
void Check(int p) {
  while (a % p == 0) {
    a /= p;
    aa++;
  }
  while (b % p == 0) {
    b /= p;
    bb++;
  }
  ans += abs(aa - bb);
  aa = bb = 0;
}
int main() {
  scanf("%d %d", &a, &b);
  Check(2);
  Check(3);
  Check(5);
  return printf("%d", a == b ? ans : -1), 0;
}
