#include <bits/stdc++.h>
using namespace std;
void BFS(map<int, int> &m1, int t) {
  queue<pair<int, int>> q1;
  set<int> set_help;
  set<int>::iterator p;
  q1.push(make_pair(t, 0));
  m1[t] = 0;
  set_help.insert(t);
  int Value, step;
  while (q1.empty() == 0) {
    Value = q1.front().first;
    step = q1.front().second;
    if (Value % 2 == 0) {
      p = set_help.find(Value / 2);
      if (p == set_help.end()) {
        m1[Value / 2] = step + 1;
        q1.push(make_pair(Value / 2, step + 1));
        set_help.insert(Value / 2);
      }
    }
    if (Value % 3 == 0) {
      p = set_help.find(Value / 3);
      if (p == set_help.end()) {
        m1[Value / 3] = step + 1;
        q1.push(make_pair(Value / 3, step + 1));
        set_help.insert(Value / 3);
      }
    }
    if (Value % 5 == 0) {
      p = set_help.find(Value / 5);
      if (p == set_help.end()) {
        m1[Value / 5] = step + 1;
        q1.push(make_pair(Value / 5, step + 1));
        set_help.insert(Value / 5);
      }
    }
    q1.pop();
  }
}
int main() {
  int a, b;
  ifstream ff("file.txt");
  cin >> a >> b;
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  map<int, int> ma, mb;
  BFS(ma, a);
  BFS(mb, b);
  map<int, int>::iterator p = ma.begin(), p1;
  int Stap_Min = INT_MAX, Step;
  for (p; p != ma.end(); p++) {
    p1 = mb.find(p->first);
    if (p1 != mb.end()) {
      Step = p->second + p1->second;
      if (Step < Stap_Min) {
        Stap_Min = Step;
      }
    }
  }
  if (Stap_Min == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << Stap_Min << endl;
  }
  return 0;
}
