#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  int r;
  while (y) r = x % y, x = y, y = r;
  return x;
}
bool factor(int a, int &cnt) {
  cnt = 0;
  while (a % 2 == 0) a /= 2, cnt++;
  while (a % 3 == 0) a /= 3, cnt++;
  while (a % 5 == 0) a /= 5, cnt++;
  if (a != 1) return false;
  return true;
}
void input() {
  int a, b, x, y;
  scanf("%d %d", &a, &b);
  int uc = gcd(a, b);
  if (factor(a / uc, x) && factor(b / uc, y))
    printf("%d", x + y);
  else
    printf("-1");
}
int main() {
  input();
  return 0;
}
