#include <bits/stdc++.h>
using namespace std;
long long gcd(long long l, long long s) {
  if (!(l % s))
    return s;
  else
    return gcd(s, l % s);
}
long long abse(long long a, long long b) {
  if (a > b) return a - b;
  return b - a;
}
long long check(long long a, vector<long long>& v) {
  while (a % 2 == 0) {
    a /= 2;
    v[0]++;
  }
  while (a % 3 == 0) {
    a /= 3;
    v[1]++;
  }
  while (a % 5 == 0) {
    a /= 5;
    v[2]++;
  }
  if (a == 1) return 0;
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1, cas;
  for (cas = 1; cas <= T; cas++) {
    long long s, l;
    cin >> s >> l;
    if (s == l) {
      cout << 0;
      return 0;
    }
    if (s > l) swap(s, l);
    long long GCD = gcd(l, s);
    vector<long long> vss(3, 0), vll(3, 0);
    l /= GCD;
    s /= GCD;
    if (check(s, vss) || check(l, vll)) {
      cout << -1;
      return 0;
    }
    int cnt =
        abse(vss[0], vll[0]) + abse(vss[1], vll[1]) + abse(vss[2], vll[2]);
    cout << cnt;
  }
  return 0;
}
