import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); BigInteger n = new BigInteger(sc.next()); BigInteger m = new BigInteger(sc.next()); HashSet set = new HashSet<>(); while (true) { BigInteger mod = n.mod(m); if (mod.equals(BigInteger.ZERO)) { System.out.println(getLastNum(n.divide(m))); return; } n = mod; if (set.contains(n)) { System.out.println(-1); return; } set.add(n); n = n.multiply(BigInteger.TEN); } } static long getLastNum(BigInteger b) { long x = b.longValue(); while (x > 0) { if (x % 10 != 0) { return x % 10; } x /= 10; } return 0; } }