#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  ;
  int n, m;
  cin >> n >> m;
  int dem = 0;
  if (m % n != 0) {
    cout << -1;
    return 0;
  }
  int sum = m / n;
  while (sum % 2 == 0) {
    sum /= 2;
    dem++;
  }
  while (sum % 3 == 0) {
    sum /= 3;
    dem++;
  }
  if (sum == 1)
    cout << dem;
  else
    cout << -1;
  return 0;
}
