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