#include <bits/stdc++.h>
using namespace std;
const int N = 0;
int n, k, x, t;
string s;
vector<int> v;
int main() {
  scanf("%d%d", &n, &k);
  int d = k / n;
  if (k % n != 0) {
    printf("-1\n");
    return 0;
  }
  int ans = 0;
  while (d % 3 == 0) {
    ans++;
    d /= 3;
  }
  while (d % 2 == 0) {
    ans++;
    d /= 2;
  }
  if (d != 1) {
    printf("-1\n");
  } else
    printf("%d\n", ans);
  return 0;
}
