#include <bits/stdc++.h>
using namespace std;
map<int, int> factor(int number) {
  map<int, int> fc;
  for (int i = 2; i <= sqrt(number); ++i) {
    while (number % i == 0) {
      fc[i]++;
      number = number / i;
    }
  }
  if (number != 1) {
    fc[number]++;
  }
  return fc;
}
bool isDevider(int n) { return n == 2 || n == 3 || n == 5; }
int spow(int n, int p) {
  int res = 1;
  for (int i = 0; i < p; ++i) {
    res *= n;
  }
  return res;
}
int bpow(int a, int b) {
  if (b == 0) return 1;
  int t = bpow(a, b / 2);
  if (b & 1) return t * t * a;
  return t * t;
}
int toNumber(const map<int, int>& factors) {
  int res = 1;
  for (const auto& f : factors) {
    res *= spow(f.first, f.second);
  }
  return res;
}
int calc(int a, int b) {
  if (a == b) {
    return 0;
  }
  int res = 0;
  auto factorA = factor(a);
  auto factorB = factor(b);
  for (int i : vector<int>{2, 3, 5}) {
    auto itA = factorA.find(i);
    auto itB = factorB.find(i);
    int ca = 0, cb = 0;
    if (itA != factorA.end() && itB != factorB.end()) {
      res += abs(itA->second - itB->second);
      itA->second = 0;
      itB->second = 0;
    } else if (itA != factorA.end()) {
      res += itA->second;
      itA->second = 0;
    } else if (itB != factorB.end()) {
      res += itB->second;
      itB->second = 0;
    }
  }
  return toNumber(factorA) == toNumber(factorB) ? res : -1;
}
int main() {
  int a, b;
  cin >> a >> b;
  cout << calc(a, b) << endl;
  return 0;
}
