#include <bits/stdc++.h>
using namespace std;
long long big = 1000000007;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long a, b;
  cin >> a >> b;
  int g = gcd(a, b);
  a /= g;
  b /= g;
  int ctr = 0;
  while (a % 2 == 0) {
    ctr += 1;
    a /= 2;
  }
  while (a % 3 == 0) {
    ctr += 1;
    a /= 3;
  }
  while (a % 5 == 0) {
    ctr += 1;
    a /= 5;
  }
  if (a != 1) {
    cout << -1 << '\n';
    return 0;
  }
  while (b % 2 == 0) {
    ctr += 1;
    b /= 2;
  }
  while (b % 3 == 0) {
    ctr += 1;
    b /= 3;
  }
  while (b % 5 == 0) {
    ctr += 1;
    b /= 5;
  }
  if (b != 1) {
    cout << -1 << '\n';
    return 0;
  }
  cout << ctr << '\n';
  return 0;
}
