#include <bits/stdc++.h>
using namespace std;
long long int a, b;
int main() {
  while (cin >> a >> b) {
    if (a == b)
      cout << 0 << endl;
    else {
      int a1, a2, a3, b1, b2, b3;
      a1 = a2 = a3 = b1 = b2 = b3 = 0;
      int aa = a, bb = b;
      bool flag = 1;
      for (; flag != 0;) {
        flag = 0;
        if (aa % 2 == 0) {
          flag = 1;
          aa = aa / 2;
          a1++;
        }
        if (aa % 3 == 0) {
          flag = 1;
          aa = aa / 3;
          a2++;
        }
        if (aa % 5 == 0) {
          flag = 1;
          aa = aa / 5;
          a3++;
        }
      }
      flag = 1;
      for (; flag != 0;) {
        flag = 0;
        if (bb % 2 == 0) {
          flag = 1;
          bb = bb / 2;
          b1++;
        }
        if (bb % 3 == 0) {
          flag = 1;
          bb = bb / 3;
          b2++;
        }
        if (bb % 5 == 0) {
          flag = 1;
          bb = bb / 5;
          b3++;
        }
      }
      if (aa == bb) {
        int aaa = a1 - b1;
        int bbb = a2 - b2;
        int ccc = a3 - b3;
        if (aaa < 0) aaa = -aaa;
        if (bbb < 0) bbb = -bbb;
        if (ccc < 0) ccc = -ccc;
        int ans;
        ans = aaa + bbb + ccc;
        cout << ans << endl;
      } else
        cout << -1 << endl;
    }
  }
  return 0;
}
