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