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