#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (x < y) swap(x, y);
  if (x % y == 0) return y;
  return gcd(y, x % y);
}
int main() {
  int num[3] = {2, 3, 5};
  int a, b;
  cin >> a >> b;
  int xa = a, xb = b;
  for (int i = 0; i < 3; i++)
    while (xa % num[i] == 0) {
      xa /= num[i];
    }
  for (int i = 0; i < 3; i++)
    while (xb % num[i] == 0) {
      xb /= num[i];
    }
  if (xa != xb)
    cout << "-1" << endl;
  else {
    int ans = 0;
    int k = a / gcd(a, b);
    for (int i = 0; i < 3; i++)
      while (k % num[i] == 0) {
        k /= num[i];
        ans++;
      }
    k = b / gcd(a, b);
    for (int i = 0; i < 3; i++)
      while (k % num[i] == 0) {
        k /= num[i];
        ans++;
      }
    cout << ans << endl;
  }
  return 0;
}
