#include <bits/stdc++.h>
using namespace std;
int op_cnt[6];
int main() {
  int a, b, s = 0;
  cin >> a >> b;
  for (int n = 2; n <= 5; n++) {
    while (a % n == 0) a /= n, op_cnt[n]++;
    while (b % n == 0) b /= n, op_cnt[n]--;
    s += abs(op_cnt[n]);
  }
  cout << (a == b ? s : -1);
  return 0;
}
