import java.math.BigDecimal; import java.util.Scanner; public class Main { private static long n; private static long m; public static void main(String[] args) { Scanner cin = new Scanner(System.in); n = Long.parseLong(cin.next()); m = Long.parseLong(cin.next()); cin.close(); calculate(); } private static void calculate() { long target = m; while (target % 2 == 0) { target /= 2; } while (target % 5 == 0) { target /= 5; } if (n % target != 0) { System.out.println(-1); } else { String resultStr = new BigDecimal(n).divide(new BigDecimal(m)).toString(); char[] charArray = resultStr.toCharArray(); for (int i = charArray.length - 1; i >= 0; i--) { if (charArray[i] != '0') { System.out.println(charArray[i]); break; } } } } }