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