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