#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, m;
  cin >> n >> m;
  if (n == m) {
    cout << 0 << endl;
    return 0;
  }
  if (m % n) {
    cout << "-1" << endl;
    return 0;
  }
  int64_t a(m / n);
  int ans(0);
  while (a % 2 == 0) {
    ++ans;
    a >>= 1;
  }
  while (a % 3 == 0) {
    ++ans;
    a /= 3;
  }
  if (a == 1) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
