#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0, val[10], i, k = 0;
  cin >> n >> m;
  if (n == m) {
    cout << "0" << endl;
    return 0;
  }
  int arr[] = {2, 3, 5};
  for (i = 0; i < 3; i++) {
    int count = 0;
    if (n % arr[i] == 0) {
      while (n % arr[i] == 0) {
        n /= arr[i];
        count++;
      }
    }
    val[k++] = count;
  }
  for (i = 0; i < 3; i++) {
    int count = 0;
    if (m % arr[i] == 0) {
      while (m % arr[i] == 0) {
        m /= arr[i];
        count++;
      }
    }
    val[k++] = count;
  }
  if (n != m)
    cout << "-1" << endl;
  else {
    for (int i = 0; i < 3; i++) {
      ans += abs(val[3 + i] - val[i]);
    }
    cout << ans << endl;
  }
  return 0;
}
