#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  int r = a % b;
  if (r == 0) return b;
  return gcd(b, r);
}
int main() {
  int a, b;
  cin >> a >> b;
  int g = gcd(a, b);
  int foxa = a / g;
  int foxb = b / g;
  int cnt = 0;
  while (foxa % 2 == 0 || foxa % 3 == 0 || foxa % 5 == 0) {
    if (foxa % 2 == 0) {
      foxa /= 2;
      cnt++;
    }
    if (foxa % 3 == 0) {
      foxa /= 3;
      cnt++;
    }
    if (foxa % 5 == 0) {
      foxa /= 5;
      cnt++;
    }
  }
  while (foxb % 2 == 0 || foxb % 3 == 0 || foxb % 5 == 0) {
    if (foxb % 2 == 0) {
      foxb /= 2;
      cnt++;
    }
    if (foxb % 3 == 0) {
      foxb /= 3;
      cnt++;
    }
    if (foxb % 5 == 0) {
      foxb /= 5;
      cnt++;
    }
  }
  if (foxa == 1 && foxb == 1)
    cout << cnt;
  else
    cout << -1;
}
