#include <bits/stdc++.h>
using namespace std;
int count(int& x, int y) {
  int cnt = 0;
  while (x % y == 0) {
    ++cnt;
    x /= y;
  }
  return cnt;
}
int main() {
  int n, m, div, res = 0;
  cin >> n >> m;
  if (m % n != 0) {
    cout << -1;
    return 0;
  }
  div = m / n;
  res += count(div, 3);
  res += count(div, 2);
  if (div != 1) {
    cout << -1;
  } else {
    cout << res;
  }
  return 0;
}
