#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m, t, x, z1 = 0, z2 = 0;
  cin >> n >> m;
  if (n == m)
    cout << 0;
  else if (n > m)
    cout << -1;
  else if (m % n != 0)
    cout << -1;
  else {
    t = m / n;
    x = t;
    while (t % 2 == 0 && t > 0) {
      z1++;
      t = t / 2;
    }
    while (t % 3 == 0 && t > 0) {
      z2++;
      t = t / 3;
    }
    t = pow(2, z1) * pow(3, z2);
    if (x == t)
      cout << z1 + z2;
    else
      cout << -1;
  }
}
