#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n) != EOF) {
    int t = gcd(m, n);
    int a = m / t, b = n / t;
    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 == 1 && b == 1)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
}
