#include <bits/stdc++.h>
using namespace std;
const int N = int(1e5) + 10;
int a, b, ans;
int main() {
  scanf("%d%d", &a, &b);
  int primes[] = {2, 3, 5};
  for (int p : primes) {
    int x = 0, y = 0;
    while (a % p == 0) a /= p, x++;
    while (b % p == 0) b /= p, y++;
    ans += abs(x - y);
  }
  if (a != b)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
