#include <bits/stdc++.h>
using namespace std;
long long a, b, ans;
long long gcd(int a, int b) {
  while (b != 0) {
    long long r = b;
    b = a % b;
    a = r;
  }
  return a;
}
int main() {
  scanf("%lld%lld", &a, &b);
  if (a == b) {
    printf("0");
    return 0;
  }
  long long c;
  if (b > a) c = a, a = b, b = c;
  c = gcd(a, b);
  a = a * b / c / c;
  while (a % 2 == 0) {
    a /= 2;
    ans++;
  }
  while (a % 3 == 0) {
    a /= 3;
    ans++;
  }
  while (a % 5 == 0) {
    a /= 5;
    ans++;
  }
  if (a != 1 && a != 0) ans = -1;
  printf("%lld", ans);
}
