#include <bits/stdc++.h>
using namespace std;
int n, t, b, c;
int sum[105][3], a[105];
int gcd(int a, int b) {
  while (b) {
    int t = a % b;
    a = b;
    b = t;
  }
  return a;
}
bool ok(int va) {
  while (va % 2 == 0) va /= 2;
  while (va % 3 == 0) va /= 3;
  while (va % 5 == 0) va /= 5;
  return va == 1;
}
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a == b)
    printf("0\n");
  else {
    int pre = gcd(a, b);
    int prea = a / pre;
    int preb = b / pre;
    if (ok(prea) && ok(preb)) {
      int sum = 0;
      while (prea % 2 == 0) {
        prea /= 2;
        sum++;
      }
      while (prea % 3 == 0) {
        prea /= 3;
        sum++;
      }
      while (prea % 5 == 0) {
        prea /= 5;
        sum++;
      }
      while (preb % 2 == 0) {
        preb /= 2;
        sum++;
      }
      while (preb % 3 == 0) {
        preb /= 3;
        sum++;
      }
      while (preb % 5 == 0) {
        preb /= 5;
        sum++;
      }
      printf("%d\n", sum);
    } else
      printf("-1\n");
  }
  return 0;
}
