#include <bits/stdc++.h>
using namespace std;
int a, b, k1, k2, x[300000], y[300000];
set<int> s;
int f(int p) {
  int res = 0;
  while (p % 2 == 0) {
    res++;
    p /= 2;
  }
  while (p % 3 == 0) {
    res++;
    p /= 3;
  }
  while (p % 5 == 0) {
    res++;
    p /= 5;
  }
  if (p != 1) return 1000000000;
  return res;
}
int main() {
  cin >> a >> b;
  int k1 = 0, k2 = 0;
  for (int i = 1; i <= a; i++) {
    if (i * i > a) break;
    if (a % i == 0) {
      k1++;
      x[k1] = i;
      if (i != a / i) {
        k1++;
        x[k1] = a / i;
      }
    }
  }
  for (int i = 1; i <= b; i++) {
    if (i * i > b) break;
    if (b % i == 0) {
      s.insert(i);
      if (i != b / i) {
        s.insert(b / i);
      }
    }
  }
  sort(x + 1, x + k1 + 1);
  sort(y + 1, y + k2 + 1);
  int j = 1, ans = 1000000000;
  for (int i = 1; i <= k1; i++) {
    if (s.find(x[i]) != s.end()) {
      ans = min(ans, f(a / x[i]) + f(b / x[i]));
    }
  }
  if (ans != 1000000000)
    cout << ans;
  else
    cout << -1;
  return 0;
}
