#include <bits/stdc++.h>
using namespace std;
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const long long inf = 1e9;
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int div : {2, 3, 5}) {
    int pa = 0;
    while (a % div == 0) {
      a /= div;
      pa++;
    }
    int pb = 0;
    while (b % div == 0) {
      b /= div;
      pb++;
    }
    ans += abs(pa - pb);
  }
  if (a != b)
    cout << -1 << "\n";
  else
    cout << ans << "\n";
}
