#include <bits/stdc++.h>
using namespace std;
int a[2];
int f[2][3];
void cal(int i) {
  while (a[i] % 2 == 0) {
    f[i][0]++;
    a[i] /= 2;
  }
  while (a[i] % 3 == 0) {
    f[i][1]++;
    a[i] /= 3;
  }
  while (a[i] % 5 == 0) {
    f[i][2]++;
    a[i] /= 5;
  }
}
int main() {
  scanf("%d %d", &a[0], &a[1]);
  if (a[0] == a[1]) {
    printf("0\n");
  } else {
    cal(0);
    cal(1);
    if (a[0] != a[1]) {
      printf("-1\n");
    } else {
      int ret = 0;
      for (int i = 0; i < 3; ++i) {
        ret += abs(f[0][i] - f[1][i]);
      }
      printf("%d\n", ret);
    }
  }
  return 0;
}
