#include <bits/stdc++.h>
using namespace std;
long long a, b, c;
long long x, y, z;
int main() {
  long long n, m, ans = 0;
  bool t1 = 1, t2 = 1;
  cin >> n >> m;
  if (m == n)
    cout << 0;
  else {
    while (t1) {
      t1 = 0;
      if (n % 2 == 0) {
        a++;
        t1 = 1;
        n /= 2;
      } else if (n % 3 == 0) {
        b++;
        t1 = 1;
        n /= 3;
      } else if (n % 5 == 0) {
        c++;
        t1 = 1;
        n /= 5;
      }
    }
    while (t2) {
      t2 = 0;
      if (m % 2 == 0) {
        x++;
        t2 = 1;
        m /= 2;
      } else if (m % 3 == 0) {
        y++;
        t2 = 1;
        m /= 3;
      } else if (m % 5 == 0) {
        z++;
        t2 = 1;
        m /= 5;
      }
    }
    if (n != m)
      cout << -1;
    else {
      ans += abs(a - x);
      ans += abs(b - y);
      ans += abs(c - z);
      cout << ans;
    }
  }
}
