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