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