#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, b, counta2 = 0, counta3 = 0, counta5 = 0, countb2 = 0,
                  countb3 = 0, countb5 = 0;
  cin >> a >> b;
  while (a % 2 == 0) {
    a = a / 2;
    counta2++;
  }
  while (a % 3 == 0) {
    a = a / 3;
    counta3++;
  }
  while (a % 5 == 0) {
    a = a / 5;
    counta5++;
  }
  while (b % 2 == 0) {
    b = b / 2;
    countb2++;
  }
  while (b % 3 == 0) {
    b = b / 3;
    countb3++;
  }
  while (b % 5 == 0) {
    b = b / 5;
    countb5++;
  }
  if (a != b) {
    cout << "-1" << '\n';
  } else {
    long long ans = abs(counta2 - countb2) + abs(counta3 - countb3) +
                    abs(counta5 - countb5);
    cout << ans << '\n';
  }
  return 0;
}
