#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int inf = 2 * 1000 * 1000 * 1000;
const int maxn = 1000 * 1000;
map<int, map<int, int> > was, d;
int calc(int a, int b) {
  if (b < a) swap(a, b);
  if (was[a][b]) return d[a][b];
  was[a][b] = true;
  d[a][b] = inf;
  if (a == b) return d[a][b] = 0;
  if (b % 2 == 0) d[a][b] = min(d[a][b], calc(a, b / 2) + 1);
  if (b % 3 == 0) d[a][b] = min(d[a][b], calc(a, b / 3) + 1);
  if (b % 5 == 0) d[a][b] = min(d[a][b], calc(a, b / 5) + 1);
  return d[a][b];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (calc(a, b) != inf)
    cout << calc(a, b);
  else
    cout << -1;
  return 0;
}
