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