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