#include <bits/stdc++.h>
using namespace std;
long long nod(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  if (a > b)
    return nod(a % b, b);
  else
    return nod(a, b % a);
}
int main() {
  long long a, b;
  cin >> a >> b;
  long long q = nod(a, b);
  long long a1 = a / q, b1 = b / q;
  long int res = 0;
  while (a1 % 2 == 0) {
    a1 /= 2;
    res++;
  }
  while (a1 % 3 == 0) {
    a1 /= 3;
    res++;
  }
  while (a1 % 5 == 0) {
    a1 /= 5;
    res++;
  }
  while (b1 % 2 == 0) {
    b1 /= 2;
    res++;
  }
  while (b1 % 3 == 0) {
    b1 /= 3;
    res++;
  }
  while (b1 % 5 == 0) {
    b1 /= 5;
    res++;
  }
  if (a1 == 1 && b1 == 1)
    cout << res;
  else
    cout << -1;
}
