#include <bits/stdc++.h>
using namespace std;
int di(int &n, int x) {
  int count = 0;
  while (n % x == 0) {
    n /= x;
    count++;
  }
  return count;
}
int main() {
  int a, b;
  cin >> a >> b;
  int x[3], y[3];
  x[0] = di(a, 2);
  x[1] = di(a, 3);
  x[2] = di(a, 5);
  y[0] = di(b, 2);
  y[1] = di(b, 3);
  y[2] = di(b, 5);
  if (a != b)
    cout << -1;
  else {
    cout << abs(x[0] - y[0]) + abs(x[1] - y[1]) + abs(x[2] - y[2]);
  }
  cin >> a;
  return 0;
}
