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