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