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