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