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