#include <bits/stdc++.h>
using namespace std;
int a, b;
int ans = 0;
bool ok = true;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
void solve(int a) {
  while (a % 2 == 0) {
    a /= 2;
    ans++;
  }
  while (a % 3 == 0) {
    a /= 3;
    ans++;
  }
  while (a % 5 == 0) {
    a /= 5;
    ans++;
  }
  if (a != 1) ok = false;
}
int main() {
  scanf("%d%d", &a, &b);
  int x = gcd(a, b);
  a = a / x;
  b = b / x;
  solve(a);
  solve(b);
  if (ok)
    printf("%d\n", ans);
  else
    puts("-1");
  return 0;
}
