#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0, d[6] = {};
  for (int i = 2; i < 6; i++) {
    while (a % i == 0) a /= i, d[i]++;
    while (b % i == 0) b /= i, d[i]--;
    ans += abs(d[i]);
  }
  cout << (a - b ? -1 : ans);
  return 0;
}
