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