#include <bits/stdc++.h>
using namespace std;
int n, a, b, A[6], B[6];
int main() {
  cin >> a >> b;
  for (n = 2; n < 6; n++) {
    while (a % n == 0) {
      a /= n;
      A[n]++;
    }
    while (b % n == 0) {
      b /= n;
      B[n]++;
    }
  }
  int res =
      (a != b) ? -1 : abs(A[2] - B[2]) + abs(A[3] - B[3]) + abs(A[5] - B[5]);
  cout << res << endl;
}
