#include <bits/stdc++.h>
using namespace std;
int trim(int n, int s[]) {
  int v[3] = {2, 3, 5};
  for (int i = 0; i < 3; i++) {
    s[i] = 0;
    while (n % v[i] == 0) {
      n /= v[i];
      s[i]++;
    }
  }
  return n;
}
int main() {
  int a, b;
  int s1[3], s2[3];
  while (2 == scanf("%d%d", &a, &b)) {
    if (a == b) {
      printf("0\n");
      continue;
    }
    a = trim(a, s1);
    b = trim(b, s2);
    if ((a > 1 || b > 1) && a != b) {
      printf("-1\n");
      continue;
    }
    int result = 0;
    for (int i = 0; i < 3; i++) {
      result += max(s1[i], s2[i]) - min(s1[i], s2[i]);
    }
    printf("%d\n", result);
  }
  return 0;
}
