#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      if (b % i == 0) v.push_back(i);
      if (b % (a / i) == 0) v.push_back(a / i);
    }
  }
  int ans = -1;
  for (int i = 0; i < v.size(); i++) {
    int d[2] = {a / v[i], b / v[i]};
    int p[2] = {0, 0};
    int a[3] = {2, 3, 5};
    for (int k = 0; k < 2; k++) {
      for (int j = 0; j < 3; j++) {
        while (d[k] % a[j] == 0) {
          d[k] /= a[j];
          p[k]++;
        }
      }
    }
    if (d[0] == 1 && d[1] == 1) {
      if (ans == -1 || p[0] + p[1] < ans) ans = p[0] + p[1];
    }
  }
  cout << ans << endl;
  return 0;
}
