#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > st;
map<pair<int, int>, int> mp;
queue<pair<int, int> > q;
int main() {
  int a, b;
  cin >> a >> b;
  q.push(make_pair(a, b));
  st.insert(make_pair(a, b));
  mp[make_pair(a, b)] = 0;
  while (!q.empty()) {
    pair<int, int> nows = q.front();
    int step = mp[nows];
    int x = nows.first, y = nows.second;
    q.pop();
    if (x == y) {
      cout << step << endl;
      return 0;
    }
    pair<int, int> np;
    if (x % 2 == 0) {
      np = make_pair(x / 2, y);
      if (st.find(np) == st.end()) {
        mp[np] = step + 1;
        st.insert(np);
        q.push(np);
      }
    }
    if (x % 3 == 0) {
      np = make_pair(x / 3, y);
      if (st.find(np) == st.end()) {
        mp[np] = step + 1;
        st.insert(np);
        q.push(np);
      }
    }
    if (x % 5 == 0) {
      np = make_pair(x / 5, y);
      if (st.find(np) == st.end()) {
        mp[np] = step + 1;
        st.insert(np);
        q.push(np);
      }
    }
    if (y % 2 == 0) {
      np = make_pair(x, y / 2);
      if (st.find(np) == st.end()) {
        mp[np] = step + 1;
        st.insert(np);
        q.push(np);
      }
    }
    if (y % 3 == 0) {
      np = make_pair(x, y / 3);
      if (st.find(np) == st.end()) {
        mp[np] = step + 1;
        st.insert(np);
        q.push(np);
      }
    }
    if (y % 5 == 0) {
      np = make_pair(x, y / 5);
      if (st.find(np) == st.end()) {
        mp[np] = step + 1;
        st.insert(np);
        q.push(np);
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
