#include <bits/stdc++.h>
int main() {
  int a, b;
  int op = 0;
  int two[2] = {0};
  int three[2] = {0};
  int five[2] = {0};
  int t1, t2;
  scanf("%d%d", &a, &b);
  while (a % 2 == 0) {
    two[0]++;
    a /= 2;
  }
  while (a % 3 == 0) {
    three[0]++;
    a /= 3;
  }
  while (a % 5 == 0) {
    five[0]++;
    a /= 5;
  }
  while (b % 2 == 0) {
    two[1]++;
    b /= 2;
  }
  while (b % 3 == 0) {
    three[1]++;
    b /= 3;
  }
  while (b % 5 == 0) {
    five[1]++;
    b /= 5;
  }
  if (a != b)
    op = -1;
  else {
    while (two[0] != 0 && two[1] != 0) {
      two[0]--;
      two[1]--;
    }
    while (three[0] != 0 && three[1] != 0) {
      three[0]--;
      three[1]--;
    }
    while (five[0] != 0 && five[1] != 0) {
      five[0]--;
      five[1]--;
    }
    op = two[0] + two[1] + three[0] + three[1] + five[0] + five[1];
  }
  printf("%d", op);
  return 0;
}
