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(); long gcd = gcd(N,M); N/=gcd; M/=gcd; long ans = ans(N,M); System.out.println(ans); } static long gcd(long x, long y){ while(true){ long z=x%y; if(z==0){break;} x=y; y=z; } return y; } static int ans(long N, long M){ long t=M; while(t%2==0){ t/=2; } while(t%5==0){ t/=5; } int r=-1; if(t==1){ BigDecimal x = new BigDecimal(N); BigDecimal y = new BigDecimal(M); BigDecimal z = x.divide(y, 1000, BigDecimal.ROUND_UNNECESSARY); String w = z.toPlainString(); for(int i=w.length()-1; i>=0; i--){ int A = w.charAt(i); if(A!='0'&&A!='.'){ r=w.charAt(i)-'0'; break; } } } return r; } }