#include <bits/stdc++.h>
using namespace std;
const int INFI = (1 << 30);
const long long INFL = (1LL << 62);
const double eps = 1e-7;
const long double pi = acos(-1.0);
const int md = 1e9 + 7;
int main() {
  int a, b;
  map<int, int> m1, m2;
  cin >> a >> b;
  m1[a] = 0;
  m2[b] = 0;
  queue<int> q;
  q.push(a);
  while (!q.empty()) {
    int x = q.front();
    int tm = m1[x];
    q.pop();
    if (x % 2 == 0 && (m1.find(x / 2) == m1.end() || tm + 1 < m1[x / 2])) {
      q.push(x / 2);
      m1[x / 2] = tm + 1;
    }
    if (x % 3 == 0 && (m1.find(x / 3) == m1.end() || tm + 1 < m1[x / 3])) {
      q.push(x / 3);
      m1[x / 3] = tm + 1;
    }
    if (x % 5 == 0 && (m1.find(x / 5) == m1.end() || tm + 1 < m1[x / 5])) {
      q.push(x / 5);
      m1[x / 5] = tm + 1;
    }
  }
  q.push(b);
  while (!q.empty()) {
    int x = q.front();
    int tm = m2[x];
    q.pop();
    if (x % 2 == 0 && (m2.find(x / 2) == m2.end() || tm + 1 < m2[x / 2])) {
      q.push(x / 2);
      m2[x / 2] = tm + 1;
    }
    if (x % 3 == 0 && (m2.find(x / 3) == m2.end() || tm + 1 < m2[x / 3])) {
      q.push(x / 3);
      m2[x / 3] = tm + 1;
    }
    if (x % 5 == 0 && (m2.find(x / 5) == m2.end() || tm + 1 < m2[x / 5])) {
      q.push(x / 5);
      m2[x / 5] = tm + 1;
    }
  }
  int mn = INFI;
  for (map<int, int>::iterator it = m1.begin(); it != m1.end(); it++)
    if (m2.find(it->first) != m2.end())
      mn = min(mn, m2[it->first] + it->second);
  if (mn != INFI)
    cout << mn << '\n';
  else
    cout << -1;
  return 0;
}
