import java.util.*; public class Main { static long GCD(long a, long b) { //最大公約数 if (a % b == 0 || b % a == 0) { return Math.min(a, b); } else { return GCD(a % b, b % a); } } public static void main(String[] args) { Scanner sc=new Scanner(System.in); long n=sc.nextLong(); long m=sc.nextLong(); long g=GCD(n,m); n/=g; m/=g; if(m==1){ while(n%10==0){ n/=10; } System.out.println(n%10); return; } int two=0; int five=0; boolean next=false; long c=m; do{ next=false; if(c%2==0){ c/=2; two++; next=true; } if(c%5==0){ c/=5; five++; next=true; } }while(next); int N=(int)(n%10); if(c!=1 || (two==0 && five==0)){ System.out.println(-1); return; } else if(two>0 && five>0)System.out.println(N); else if(two>0)System.out.println(5); else{ int x=0; while(x