#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  if (b % a != 0)
    cout << "-1";
  else {
    if (b / a == 1)
      cout << "0";
    else {
      int res = 0;
      long long r = b / a;
      while (r > 1) {
        if (r % 2 == 0) r = r / 2, res++;
        if (r % 3 == 0) r = r / 3, res++;
        if (r % 3 != 0 && r % 2 != 0 && r > 1) {
          res = -1;
          break;
        }
      }
      cout << res;
    }
  }
  return 0;
}
