#include <bits/stdc++.h>
using namespace std;
queue<pair<pair<int, int>, int> > q;
set<pair<int, int> > s;
int a, b;
void input() { cin >> a >> b; }
void evaluate() {
  q.push(make_pair(make_pair(a, b), 0));
  while (!q.empty()) {
    if (s.find(q.front().first) == s.end()) {
      s.insert(q.front().first);
      pair<int, int> x = q.front().first;
      int y = q.front().second;
      q.pop();
      if (x.first == x.second) {
        cout << y;
        exit(0);
      }
      y++;
      if (x.first % 2 == 0) {
        x.first /= 2;
        q.push(make_pair(x, y));
        x.first *= 2;
      }
      if (x.first % 3 == 0) {
        x.first /= 3;
        q.push(make_pair(x, y));
        x.first *= 3;
      }
      if (x.first % 5 == 0) {
        x.first /= 5;
        q.push(make_pair(x, y));
        x.first *= 5;
      }
      if (x.second % 2 == 0) {
        x.second /= 2;
        q.push(make_pair(x, y));
        x.second *= 2;
      }
      if (x.second % 3 == 0) {
        x.second /= 3;
        q.push(make_pair(x, y));
        x.second *= 3;
      }
      if (x.second % 5 == 0) {
        x.second /= 5;
        q.push(make_pair(x, y));
        x.second *= 5;
      }
    } else
      q.pop();
  }
}
int main() {
  input();
  evaluate();
  cout << -1;
  return 0;
}
