#include <bits/stdc++.h>
using namespace std;
const int inf = 2000;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  int a, b;
  vector<int> d = {2, 3, 5};
  cin >> a >> b;
  vector<int> A(3), B(3);
  for (int i = 0; i < 3; i++) {
    int cp = 0;
    while (a % d[i] == 0) a /= d[i], cp++;
    A[i] = cp;
    cp = 0;
    while (b % d[i] == 0) b /= d[i], cp++;
    B[i] = cp;
  }
  if (a == b) {
    int ans = 0;
    for (int i = 0; i < 3; i++) {
      ans += (A[i] + B[i] - 2 * min(A[i], B[i]));
    }
    cout << ans << '\n';
  } else
    cout << -1 << '\n';
  return 0;
}
