#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
int a, b;
int A[3], B[3];
int p[3] = {2, 3, 5};
int main() {
  cin >> a >> b;
  int res = 0;
  for (int i = 0; i < 3; ++i) {
    while (a % p[i] == 0) {
      a /= p[i];
      A[i]++;
    }
    while (b % p[i] == 0) {
      b /= p[i];
      B[i]++;
    }
  }
  if (a != b) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < 3; ++i) res += max(A[i], B[i]) - min(A[i], B[i]);
  cout << res << endl;
  return 0;
}
