import java.util.Scanner; public class Yukicoder25 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long M = sc.nextLong(); long div; while ((div = gcd(N, M)) != 1) { N /= div; M /= div; } while (M % 10L == 0L) M /= 10; N = N % 10 == 0 ? 1 : N % 10; while (M % 5L == 0L) { M /= 5; N = N * 2 % 10; } while (M % 2L == 0L) { M /= 2; N = 5; } N = M == 1 ? N : -1; System.out.println(N); } static long gcd(long a, long b) { long c, tmp; if (a < b) { tmp = a; a = b; b = tmp; } while (b != 0) { c = a % b; a = b; b = c; } return a; } }