#include <bits/stdc++.h>
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (n == k) {
    cout << 0 << endl;
    return 0;
  }
  int d = gcd(n, k);
  int a = n / d;
  int b = k / d;
  if (a % 2 != 0 && a % 3 != 0 && a % 5 != 0 && a != 1) {
    cout << -1 << endl;
    return 0;
  }
  if (b % 2 != 0 && b % 3 != 0 && b % 5 != 0 && b != 1) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  while (a != 1) {
    if (a % 2 == 0) {
      ans++;
      a /= 2;
    } else if (a % 3 == 0) {
      ans++;
      a /= 3;
    } else if (a % 5 == 0) {
      ans++;
      a /= 5;
    } else {
      printf("-1\n");
      return 0;
    }
  }
  while (b != 1) {
    if (b % 2 == 0) {
      ans++;
      b /= 2;
    } else if (b % 3 == 0) {
      ans++;
      b /= 3;
    } else if (b % 5 == 0) {
      ans++;
      b /= 5;
    } else {
      printf("-1\n");
      return 0;
    }
  }
  cout << ans << endl;
}
