#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, sum, k = 0;
  double n, m, sum1;
  scanf("%lf%lf", &n, &m);
  sum1 = m / n;
  sum = m / n;
  if (sum != sum1)
    printf("-1\n");
  else {
    while (sum % 2 == 0) {
      sum /= 2;
      k++;
    }
    while (sum % 3 == 0) {
      sum /= 3;
      k++;
    }
    if (sum != 1) k = -1;
    printf("%lld\n", k);
  }
  return 0;
}
