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