import java.math.BigInteger; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; public class Main { public static long MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); BigInteger N = new BigInteger(sc.next()); BigInteger M = new BigInteger(sc.next()); BigInteger answer = BigInteger.ZERO; HashSet already = new HashSet(); boolean found = false; for(int tt = 0; tt <= 100000; tt++){ //System.out.println(N + "/" + M); answer = answer.multiply(BigInteger.TEN); answer = answer.add(N.divide(M)); final BigInteger mod = N.mod(M); if(mod.equals(BigInteger.ZERO)){ found = true; break; } if(already.contains(mod)){ System.out.println(-1); return; } already.add(mod); N = mod.multiply(BigInteger.TEN); } if(!found){ System.out.println(-1); return; } final String output = answer.toString().replace("0", ""); System.out.println(output.charAt(output.length() - 1)); } }