#include <bits/stdc++.h>
using namespace std;
int moves(long long a, long long b);
int main() {
  long long a, b;
  cin >> a >> b;
  cout << moves(a, b) << endl;
  return 0;
}
int moves(long long a, long long b) {
  if (b % a != 0) return -1;
  if (a == b) return 0;
  long long tmp = b / a;
  int count = 0;
  while (tmp % 2 == 0) {
    tmp /= 2;
    ++count;
  }
  while (tmp % 3 == 0) {
    tmp /= 3;
    ++count;
  }
  if (tmp == 1)
    return count;
  else
    return -1;
}
