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