#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> cntodd, cnteven;
void solve() {
  long long a, b;
  cin >> a >> b;
  int compa[6] = {0, 0, 0, 0, 0, 0};
  int compb[6] = {0, 0, 0, 0, 0, 0};
  while (a % 2 == 0 or a % 5 == 0 or a % 3 == 0) {
    if (a % 2 == 0) compa[2]++, a /= 2;
    if (a % 3 == 0) compa[3]++, a /= 3;
    if (a % 5 == 0) compa[5]++, a /= 5;
  }
  while (b % 2 == 0 or b % 5 == 0 or b % 3 == 0) {
    if (b % 2 == 0) compb[2]++, b /= 2;
    if (b % 3 == 0) compb[3]++, b /= 3;
    if (b % 5 == 0) compb[5]++, b /= 5;
  }
  if (a != b)
    cout << -1 << "\n";
  else
    cout << abs(compa[2] - compb[2]) + abs(compa[3] - compb[3]) +
                abs(compa[5] - compb[5])
         << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
