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