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