#include <bits/stdc++.h>
using namespace std;
vector<int> factors;
void primeFactors(long long int n) {
  while (n % 2 == 0) {
    factors.push_back(2);
    n = n / 2;
  }
  while (n % 3 == 0) {
    factors.push_back(3);
    n = n / 3;
  }
  if (n > 2) factors.push_back(n);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int x, y;
  cin >> x >> y;
  if (y % x != 0)
    cout << -1 << endl;
  else {
    if (x == y) {
      cout << 0 << endl;
      return 0;
    }
    long long int temp = y / x;
    primeFactors(temp);
    int t = factors.size();
    if ((factors[0] == 2 || factors[0] == 3) &&
        (factors[t - 1] == 3 || factors[t - 1] == 2))
      cout << t << endl;
    else
      cout << -1 << endl;
  }
}
