#include <bits/stdc++.h>
using namespace std;
int main() {
  long long s, d;
  cin >> s >> d;
  long long k = d / s;
  if (d % s != 0) {
    cout << "-1";
    return 0;
  }
  long long c = 0;
  long long f = k;
  while (k % 2 == 0) {
    k = k / 2;
    c++;
  }
  while (k % 3 == 0) {
    k = k / 3;
    c++;
  }
  if (k == 1)
    cout << c;
  else
    cout << "-1";
}
