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