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