use std::io::Read; fn gcd(a: u64, b: u64) -> u64 { if b == 0 { a } else { gcd(b, a % b) } } 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: u32 = 0; let mut m5: u32 = 0; n /= g; m /= g; while m % 2 == 0 { m /= 2; m2 += 1; } while m % 5 == 0 { m /= 5; m5 += 1; } if m != 1 { println!("-1"); } else { if m2 > m5 { n *= 5u64.pow(m2 - m5); } else if m5 > m2 { n *= 2u64.pow(m5 - m2); } while n % 10 == 0 { n /= 10; } println!("{}", n % 10); } }