#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 5;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int a, b;
  cin >> a >> b;
  if (a < b) swap(a, b);
  int ans = 0;
  map<int, int> memoa, memob;
  queue<int> qa, qb;
  qa.push(a), qb.push(b);
  memoa[a] = 0, memob[b] = 0;
  while (!qa.empty()) {
    int x = qa.front();
    qa.pop();
    if (x % 2 == 0) {
      if (memoa.count(x / 2) == 0) {
        memoa[x / 2] = memoa[x] + 1;
        qa.push(x / 2);
      }
    }
    if (x % 3 == 0) {
      if (memoa.count(x / 3) == 0) {
        memoa[x / 3] = memoa[x] + 1;
        qa.push(x / 3);
      }
    }
    if (x % 5 == 0) {
      if (memoa.count(x / 5) == 0) {
        memoa[x / 5] = memoa[x] + 1;
        qa.push(x / 5);
      }
    }
  }
  while (!qb.empty()) {
    int x = qb.front();
    qb.pop();
    if (x % 2 == 0) {
      if (memob.count(x / 2) == 0) {
        memob[x / 2] = memob[x] + 1;
        qb.push(x / 2);
      }
    }
    if (x % 3 == 0) {
      if (memob.count(x / 3) == 0) {
        memob[x / 3] = memob[x] + 1;
        qb.push(x / 3);
      }
    }
    if (x % 5 == 0) {
      if (memob.count(x / 5) == 0) {
        memob[x / 5] = memob[x] + 1;
        qb.push(x / 5);
      }
    }
  }
  int best = INF;
  for (auto &p : memoa)
    if (memob.count(p.first)) best = min(best, p.second + memob[p.first]);
  cout << (best == INF ? -1 : best);
}
