#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, la[10] = {0}, lb[10] = {0}, ans = 0;
  scanf("%d%d", &a, &b);
  while (a % 2 == 0) {
    a /= 2;
    la[2]++;
  }
  while (a % 3 == 0) {
    a /= 3;
    la[3]++;
  }
  while (a % 5 == 0) {
    a /= 5;
    la[5]++;
  }
  while (b % 2 == 0) {
    b /= 2;
    lb[2]++;
  }
  while (b % 3 == 0) {
    b /= 3;
    lb[3]++;
  }
  while (b % 5 == 0) {
    b /= 5;
    lb[5]++;
  }
  if (a != b)
    puts("-1");
  else {
    ans += la[2] - lb[2] > 0 ? la[2] - lb[2] : lb[2] - la[2];
    ans += la[3] - lb[3] > 0 ? la[3] - lb[3] : lb[3] - la[3];
    ans += la[5] - lb[5] > 0 ? la[5] - lb[5] : lb[5] - la[5];
    printf("%d\n", ans);
  }
  return 0;
}
