#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = 2000000000;
const long long int infLL = 9000000000000000000;
const int mX = 1e9 + 123;
long long int a, b, a2 = 0, a3 = 0, a5 = 0;
void case_i() {
  cin >> a >> b;
  while (true) {
    if (a % 2 == 0) {
      a /= 2;
      a2++;
    } else if (a % 3 == 0) {
      a /= 3;
      a3++;
    } else if (a % 5 == 0) {
      a /= 5;
      a5++;
    } else
      break;
  }
  while (true) {
    if (b % 2 == 0) {
      b /= 2;
      a2--;
    } else if (b % 3 == 0) {
      b /= 3;
      a3--;
    } else if (b % 5 == 0) {
      b /= 5;
      a5--;
    } else
      break;
  }
  if (a != b)
    cout << -1 << endl;
  else
    cout << abs(a2) + abs(a3) + abs(a5) << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  case_i();
  return 0;
}
