#include <bits/stdc++.h>
using namespace std;
int dxx[] = {-1, 0, 1, 0};
int dyy[] = {0, 1, 0, -1};
bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) {
  return (a.second < b.second);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int a, b;
  cin >> a >> b;
  int pa[6] = {0}, push_back[6] = {0};
  vector<int> prime;
  prime.push_back(2);
  prime.push_back(3);
  prime.push_back(5);
  for (int k : prime) {
    while (a % k == 0) {
      pa[k]++;
      a /= k;
    }
    while (b % k == 0) {
      push_back[k]++;
      b /= k;
    }
  }
  if (a != b) {
    cout << -1 << '\n';
    return 0;
  }
  int ans = 0;
  for (auto k : prime) {
    ans += abs(pa[k] - push_back[k]);
  }
  cout << ans << '\n';
}
