#include <bits/stdc++.h>
using namespace std;
long long int is_factor(long long int a) {
  int cnt = 0;
  while (a > 1 && (a % 2 == 0 || a % 3 == 0 || a % 5 == 0)) {
    if (a % 2 == 0) {
      a = a / 2;
      cnt++;
    } else if (a % 3 == 0) {
      a = a / 3;
      cnt++;
    } else if (a % 5 == 0) {
      a = a / 5;
      cnt++;
    }
  }
  if (a == 1)
    return cnt;
  else
    return -1;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  long long int hcf = gcd(a, b);
  return ((a / hcf) * b);
}
int main() {
  long long int a, b;
  cin >> a >> b;
  long long int lcm_ = lcm(a, b);
  long long int to_div = (lcm_ / a) * (lcm_ / b);
  long long int ans = is_factor(to_div);
  cout << ans << endl;
}
