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