#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const long long INF64 = 9e18;
const long double EPS = 1e-9;
const long double PI = 3.14159265358979310000;
const int N = 100001;
const int M = 12001;
int first[12], second[12];
int main() {
  long long a, b;
  cin >> a >> b;
  if (a == b) {
    cout << 0;
    return 0;
  }
  while (a % 2 == 0) {
    a /= 2;
    first[2]++;
  }
  while (a % 3 == 0) {
    a /= 3;
    first[3]++;
  }
  while (a % 5 == 0) {
    a /= 5;
    first[5]++;
  }
  while (b % 2 == 0) {
    b /= 2;
    second[2]++;
  }
  while (b % 3 == 0) {
    b /= 3;
    second[3]++;
  }
  while (b % 5 == 0) {
    b /= 5;
    second[5]++;
  }
  if (a != b) {
    cout << -1;
    return 0;
  }
  cout << abs(first[2] - second[2]) + abs(first[3] - second[3]) +
              abs(first[5] - second[5]);
  return 0;
}
