#include <bits/stdc++.h>
constexpr auto Inf = 0X3F3F3F3F;
using namespace std;
namespace IO {
inline long long read() {
  long long o = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c > '/' && c < ':') {
    o = o * 10 + c - '0';
    c = getchar();
  }
  return o * f;
}
inline char recd() {
  char o;
  while ((o = getchar()) != 'Q' && o != 'C')
    ;
  return o;
}
}  // namespace IO
using namespace IO;
int main() {
  long long A, B;
  cin >> A >> B;
  if (A == B) {
    puts("0");
    return 0;
  }
  long long D = B / A;
  if (D * A != B) {
    puts("-1");
    return 0;
  }
  long long ans = 0;
  while (D % 3 == 0) D /= 3, ans++;
  while (D % 2 == 0) D /= 2, ans++;
  if (D != 1) {
    puts("-1");
    return 0;
  }
  cout << ans << endl;
}
