#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int a, b;
  cin >> a >> b;
  int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0;
  while (a % 2 == 0) {
    a = a / 2;
    c1++;
  }
  while (a % 3 == 0) {
    a = a / 3;
    c2++;
  }
  while (a % 5 == 0) {
    a = a / 5;
    c3++;
  }
  while (b % 2 == 0) {
    b = b / 2;
    c4++;
  }
  while (b % 3 == 0) {
    b = b / 3;
    c5++;
  }
  while (b % 5 == 0) {
    b = b / 5;
    c6++;
  }
  int res = abs(c1 - c4) + abs(c2 - c5) + abs(c3 - c6);
  if (a == b) {
    cout << res << '\n';
  } else {
    cout << "-1" << '\n';
  }
  return 0;
}
