import java.util.Scanner; /** * yukicoder no.25 * @author scache * */ public class FiniteDecimal { public static void main(String[] args) { FiniteDecimal p = new FiniteDecimal(); } public FiniteDecimal() { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long m = sc.nextLong(); // System.out.println(solve(1024L*1024*1024*1024*1024*1024*4, 625L*625*625*625*625*625)); System.out.println(solve(n, m)); } public int solve(long n, long m) { long g = gcd(n, m); m /= g; n /= g; while(n%10 == 0) n /= 10; long res = n; while(m%10==0) m /= 10; res %= 1000000000000000000L; while(m%2==0){ res *= 5; m /= 2; res %= 1000000000000000000L; } while(m%5==0){ res *= 2; m /= 5; res %= 1000000000000000000L; } if(m==1) return (int)res%10; else return -1; } private long gcd(long a, long b){ if(b==0) return a; else return gcd(b, a%b); } }