#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  long long int second;
  long long int length;
};
int main() {
  long long int m, n, i, j, flag1 = 0, flag2 = 0, flag = 0;
  vector<long long int> setter[2];
  cin >> m >> n;
  if (m == n) {
    cout << "0\n";
    return 0;
  }
  for (i = 2; m > 1;) {
    if (i > 5 && flag1 == 0) {
      flag = 1;
      break;
    }
    if (m % i == 0) {
      if (i == 2 || i == 3 || i == 5) flag1 = 1;
      setter[0].push_back(i);
      m = m / i;
    } else
      i++;
  }
  for (i = 2; n > 1 && flag == 0;) {
    if (i > 5 && flag2 == 0) {
      flag = 1;
      break;
    }
    if (n % i == 0) {
      if (i == 2 || i == 3 || i == 5) flag2 = 1;
      setter[1].push_back(i);
      n = n / i;
    } else
      i++;
  }
  long long int count = 0;
  for (i = 0, j = 0;
       flag == 0 && i < setter[0].size() && j < setter[1].size();) {
    if (setter[0][i] == setter[1][j]) {
      count += 2;
      i++;
      j++;
    } else if (setter[0][i] > setter[1][j]) {
      if (setter[1][j] > 5) {
        flag = 1;
        break;
      }
      j++;
    } else {
      if (setter[0][i] > 5) {
        flag = 1;
        break;
      }
      i++;
    }
  }
  if (flag == 0) {
    if (i == setter[0].size()) {
      for (; j < setter[1].size() && flag == 0; j++) {
        if (setter[1][j] > 5) {
          flag = 1;
          break;
        }
      }
    } else if (j == setter[1].size()) {
      for (; i < setter[0].size() && flag == 0; i++) {
        if (setter[0][i] > 5) {
          flag = 1;
          break;
        }
      }
    }
  }
  if (flag == 1)
    cout << "-1\n";
  else
    cout << setter[0].size() + setter[1].size() - count << endl;
  return 0;
}
