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