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