#include <bits/stdc++.h>
int main() {
  long long int n, m, d, count = 0, i;
  scanf("%lld%lld", &n, &m);
  if (m % n == 0) {
    d = m / n;
    while (d % 2 == 0) {
      d = d / 2;
      count++;
    }
    while (d % 3 == 0) {
      d = d / 3;
      count++;
    }
  }
  if (d == 1)
    printf("%lld", count);
  else {
    printf("-1");
  }
}
