#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  long long num[] = {2, 3, 5};
  long long n, m, p, q, d;
  long long x, y;
  long long i, j, k, cunt = 0;
  long long mark = 1;
  cin >> n >> m;
  x = n, y = m;
  for (i = 0; i < 3; i++) {
    while (n % num[i] == 0) n /= num[i];
    while (m % num[i] == 0) m /= num[i];
  }
  if (n != m) {
    cout << -1 << endl;
    return 0;
  }
  d = gcd(x, y);
  p = x / d;
  q = y / d;
  for (i = 0; i < 3; i++) {
    while (p % num[i] == 0) {
      p /= num[i];
      cunt++;
    }
    while (q % num[i] == 0) {
      q /= num[i];
      cunt++;
    }
  }
  cout << cunt << endl;
  return 0;
}
