#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 1;
const int INF = 1e9 + 123;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
void func(int &a, int &acnt2, int &acnt3, int &acnt5) {
  while (a % 2 == 0) {
    a /= 2;
    ++acnt2;
  }
  while (a % 3 == 0) {
    a /= 3;
    ++acnt3;
  }
  while (a % 5 == 0) {
    a /= 5;
    ++acnt5;
  }
}
int a, b, acnt2, acnt3, acnt5, bcnt2, bcnt3, bcnt5;
int main() {
  ios_base ::sync_with_stdio(0);
  cin >> a >> b;
  func(a, acnt2, acnt3, acnt5);
  func(b, bcnt2, bcnt3, bcnt5);
  if (a == b) {
    cout << abs(bcnt2 - acnt2) + abs(bcnt3 - acnt3) + abs(bcnt5 - acnt5);
  } else {
    cout << -1;
  }
  return 0;
}
