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