#include <bits/stdc++.h>
using namespace std;
namespace ZBXW {
void divide(int& x, int* cnt) {
  while (x % 2 == 0) {
    x /= 2;
    ++cnt[0];
  }
  while (x % 3 == 0) {
    x /= 3;
    ++cnt[1];
  }
  while (x % 5 == 0) {
    x /= 5;
    ++cnt[2];
  }
}
void __main__() {
  int a, b;
  cin >> a >> b;
  int cnt_a[3] = {0, 0, 0};
  int cnt_b[3] = {0, 0, 0};
  divide(a, cnt_a);
  divide(b, cnt_b);
  if (a != b) {
    cout << -1 << endl;
  } else {
    cout << (abs(cnt_a[0] - cnt_b[0]) + abs(cnt_a[1] - cnt_b[1]) +
             abs(cnt_a[2] - cnt_b[2]))
         << endl;
  }
}
}  // namespace ZBXW
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ZBXW::__main__();
  return 0;
}
