#include <bits/stdc++.h>
using namespace std;
int hcf(int a, int b) {
  if (a == 0) return b;
  if (b == 0) return a;
  while (b % a != 0) {
    int t = b % a;
    b = a;
    a = t;
  }
  return a;
}
int main() {
  int a, b;
  cin >> a >> b;
  if (a == b) {
    cout << 0 << "\n";
    return 0;
  } else {
    if (a > b) {
      int t = a;
      a = b;
      b = t;
    }
    int x = hcf(a, b);
    int c = 0;
    a /= x;
    b /= x;
    while (a != 1) {
      if (a % 2 == 0)
        a /= 2;
      else if (a % 3 == 0)
        a /= 3;
      else if (a % 5 == 0)
        a /= 5;
      else {
        cout << -1 << "\n";
        return 0;
      }
      c++;
    }
    while (b != 1) {
      if (b % 2 == 0)
        b /= 2;
      else if (b % 3 == 0)
        b /= 3;
      else if (b % 5 == 0)
        b /= 5;
      else {
        cout << -1 << "\n";
        return 0;
      }
      c++;
    }
    cout << c << "\n";
  }
}
