#include <bits/stdc++.h>
using namespace std;
int nok(int a, int b) {
  while (a != b) {
    if (a >= b)
      a = a - b;
    else
      b = b - a;
  }
  return min(a, b);
}
int main() {
  int a, b;
  cin >> a >> b;
  int k = nok(a, b);
  a = a / k;
  b = b / k;
  int t1 = 0, t2 = 0, t;
  while (a % 2 == 0) {
    a = a / 2;
    t1++;
  }
  while (a % 3 == 0) {
    a = a / 3;
    t1++;
  }
  while (a % 5 == 0) {
    a = a / 5;
    t1++;
  }
  while (b % 2 == 0) {
    b = b / 2;
    t2++;
  }
  while (b % 3 == 0) {
    b = b / 3;
    t2++;
  }
  while (b % 5 == 0) {
    b = b / 5;
    t2++;
  }
  if (a == 1 && b == 1) {
    t = t1 + t2;
  } else {
    t = -1;
  }
  cout << t;
  return 0;
}
