import java.util.Scanner; public class Main_yukicoder25 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long m = sc.nextLong(); long gcd = gcd(n, m); n /= gcd; m /= gcd; int cnt2 = 0; while (m % 2 == 0) { cnt2++; m /= 2; } int cnt5 = 0; while (m % 5 == 0) { cnt5++; m /= 5; } while (n % 10 == 0) { n /= 10; } n %= 10; if (m != 1) { System.out.println(-1); } else if (cnt2 == cnt5) { System.out.println(n); } else if (cnt2 > cnt5) { System.out.println(5); } else { long tmp = 1; for (int i = 0; i < cnt5 - cnt2; i++) { tmp *= 2; } System.out.println(tmp * n % 10); } sc.close(); } private static long gcd(long n, long m) { if (m == 0) { return n; } else { return gcd(m, n % m); } } }