#include <bits/stdc++.h>
using namespace std;
int a, b;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  cin >> a >> b;
  int gcdab = gcd(a, b);
  a /= gcdab;
  b /= gcdab;
  int ans = 0;
  while (a % 2 == 0) a /= 2, ans++;
  while (a % 3 == 0) a /= 3, ans++;
  while (a % 5 == 0) a /= 5, ans++;
  while (b % 2 == 0) b /= 2, ans++;
  while (b % 3 == 0) b /= 3, ans++;
  while (b % 5 == 0) b /= 5, ans++;
  if (a == b)
    cout << ans << endl;
  else
    cout << "-1" << endl;
  return 0;
}
