#include <bits/stdc++.h>
using namespace std;
vector<int> Powers(int n) {
  vector<int> powers;
  for (int i = 2; i * i <= n; i++) {
    int tmp = n;
    int count = 0;
    while (n % i == 0) {
      powers.push_back(i);
      n /= i;
    }
  }
  if (n != 1) {
    powers.push_back(n);
  }
  return powers;
}
int main() {
  int a, b;
  cin >> a >> b;
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> v1 = Powers(a);
  int a2 = 0, a3 = 0, a5 = 0, b2 = 0, b3 = 0, b5 = 0;
  int x1 = 1, y1 = 1;
  vector<int> x, y;
  for (int i = 0; i < v1.size(); i++) {
    if (v1[i] == 2) {
      a2++;
    } else if (v1[i] == 3) {
      a3++;
    } else if (v1[i] == 5) {
      a5++;
    } else {
      x1 *= v1[i];
      x.push_back(v1[i]);
    }
  }
  vector<int> v2 = Powers(b);
  for (int i = 0; i < v2.size(); i++) {
    if (v2[i] == 2) {
      b2++;
    } else if (v2[i] == 3) {
      b3++;
    } else if (v2[i] == 5) {
      b5++;
    } else {
      y1 *= v2[i];
      y.push_back(v2[i]);
    }
  }
  if (x1 != y1) {
    cout << -1 << endl;
  } else {
    int ans = abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5);
    cout << ans << endl;
  }
  return 0;
}
