#include <bits/stdc++.h>
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (b % a)
    puts("-1");
  else {
    int x = b / a, cnt = 0;
    while (x % 2 == 0) x = x / 2, ++cnt;
    while (x % 3 == 0) x = x / 3, ++cnt;
    if (x != 1)
      puts("-1");
    else
      printf("%d\n", cnt);
  }
  return 0;
}
