use std::io::Read; fn gcd(a: u64, b: u64) -> u64 { if b == 0 { a } else { gcd(b, a % b) } } fn mod_pow(mut x: u64, mut e: u64) -> u64 { let mut res: u64 = 1; while e > 0 { if e % 2 == 1 { res = res * x % 10; } x = x * x % 10; e >>= 1; } res } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let mut n: u64 = itr.next().unwrap().parse().unwrap(); let mut m: u64 = itr.next().unwrap().parse().unwrap(); let g: u64 = gcd(n, m); let mut m2: u64 = 0; let mut m5: u64 = 0; n /= g; m /= g; while m % 2 == 0 { m /= 2; m2 += 1; } while m % 5 == 0 { m /= 5; m5 += 1; } while n % 10 == 0 { n /= 10; } if m != 1 { println!("-1"); } else { if m2 > m5 { n = (n % 10 * mod_pow(5, m2 - m5)) % 10; } else if m5 > m2 { n = (n % 10 * mod_pow(2, m5 - m2)) % 10; } println!("{}", n); } }