use std::io::Read; 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 mut i = 2; let mut nprime = std::collections::HashMap::new(); let mut mprime = std::collections::HashMap::new(); while i * i <= n { while n % i == 0 { let num = nprime.entry(i as usize).or_insert(0); mprime.entry(i as usize).or_insert(0); *num += 1; n /= i; } i += 1; } if n != 1 { let num = nprime.entry(n as usize).or_insert(0); mprime.entry(n as usize).or_insert(0); *num += 1; } i = 2; while i * i <= m { while m % i == 0 { nprime.entry(i as usize).or_insert(0); let num = mprime.entry(i as usize).or_insert(0); *num += 1; m /= i; } i += 1; } if m != 1 { nprime.entry(m as usize).or_insert(0); let num = mprime.entry(m as usize).or_insert(0); *num += 1; } let mut ans: u64 = 1; let mut n2: u64 = 0; let mut m2: u64 = 0; let mut n5: u64 = 0; let mut m5: u64 = 0; for (&key, &value) in &mprime { if key == 2 { n2 = nprime[&key]; m2 = value; } else if key == 5 { n5 = nprime[&key]; m5 = value; } else { if nprime[&key] < value { println!("-1"); return; } else { ans *= (key as u64).pow((nprime[&key] - value) as u32) % 10; } } } if n2 < m2 { n5 += m2 - n2; n2 = m2; } if n5 < m5 { n2 += m5 - n5; n5 = m5; } ans *= 2u64.pow((n2 - m2) as u32) % 10; ans *= 5u64.pow((n5 - m5) as u32) % 10; while ans % 10 == 0 { ans /= 10; } println!("{}", ans % 10); }