#include <bits/stdc++.h>
int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  int result, count = 0;
  int m;
  if (b % a || b < a) {
    result = -1;
  } else {
    m = b / a;
    while (m % 2 == 0) {
      count++;
      m /= 2;
    }
    while (m % 3 == 0) {
      count++;
      m /= 3;
    }
    if (m == 1) {
      result = count;
    } else {
      result = -1;
    }
  }
  printf("%d", result);
  return 0;
}
