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