#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, p, count = 0, count1 = 0;
  cin >> n >> m;
  p = m / n;
  if (p % 2 == 0 || p % 3 == 0 || n == m) {
    while (p % 3 == 0) {
      n = n * 3;
      p = p / 3;
      count++;
    }
    while (p % 2 == 0) {
      n = n * 2;
      p = p / 2;
      count1++;
    }
    if (n == m)
      cout << count + count1 << endl;
    else
      cout << -1 << endl;
  } else
    cout << -1 << endl;
}
