#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long x, y, ans = 0;
  cin >> x >> y;
  int arr[3] = {2, 3, 5};
  for (int i = 0; i < 3; i++) {
    int c1 = 0, c2 = 0;
    while (x % arr[i] == 0) {
      x /= arr[i];
      c1++;
    }
    while (y % arr[i] == 0) {
      y /= arr[i];
      c2++;
    }
    ans += max(c1, c2) - min(c1, c2);
  }
  if (x == y)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
