#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  bool flag = true;
  int x = m / n;
  int ans = 0;
  if (m % n) {
    flag = false;
    goto end;
  }
  while (x % 2 == 0) {
    x /= 2;
    ans++;
  }
  while (x % 3 == 0) {
    x /= 3;
    ans++;
  }
  if (x > 1) flag = false;
end:
  if (flag)
    printf("%d", ans);
  else
    printf("-1");
  return 0;
}
