#include <bits/stdc++.h>
using namespace std;
long long int m, n, c = 0, k = 0, a = 0, b = 0, temp, MAX = 0, MIN = 999999999,
                    sum = 0;
long long int i, j;
int main() {
  cin >> n >> m;
  long long int x = m / n;
  c = 0;
  while (x % 2 == 0 || x % 3 == 0) {
    c++;
    if (x == 1) break;
    if (x % 3 == 0)
      x /= 3;
    else
      x /= 2;
  }
  if (x != 1 || m % n) c = -1;
  cout << c << endl;
}
