#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000000;
map<int, int> mp, mp2;
map<int, int>::iterator it;
int n, m;
int tmp[3] = {2, 3, 5}, flag, t;
void bfs(int val, int cnt) {
  queue<int> q;
  mp[val] = cnt;
  q.push(val);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < 3; ++i) {
      if (x % tmp[i] == 0 && x != 0) {
        if (mp.count(x / tmp[i]) == 0) {
          mp[x / tmp[i]] = mp[x] + 1;
          q.push(x / tmp[i]);
        }
      }
    }
  }
}
void bfs1(int val, int cnt) {
  if (mp.count(val) != 0) {
    flag = mp[val];
    return;
  }
  queue<int> q;
  mp2[val] = cnt;
  q.push(val);
  while (!q.empty() && flag == -1) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < 3 && flag == -1; ++i) {
      if (x % tmp[i] == 0 && x != 0 && flag == -1) {
        if (mp.count(x / tmp[i]) != 0 && flag == -1) {
          flag = mp[x / tmp[i]] + mp2[x] + 1;
          return;
        }
        if (mp2.count(x / tmp[i]) == 0) {
          mp2[x / tmp[i]] = mp2[x] + 1;
          q.push(x / tmp[i]);
        }
      }
    }
  }
}
int main() {
  while (cin >> n >> m) {
    if (n == m) {
      cout << "0\n";
      continue;
    }
    mp.clear();
    mp2.clear();
    t = 0;
    bfs(n, 0);
    flag = -1;
    bfs1(m, 0);
    cout << flag << endl;
  }
  return 0;
}
