fn main() { let mut xx = String::new(); std::io::Read::read_to_string(&mut std::io::stdin(), &mut xx).ok(); let xx: Vec<&str> = xx.split_whitespace().collect(); let n_mod_10 = xx[0].chars().last().unwrap().to_digit(10).unwrap(); let m_mod_100: usize = xx[1][(xx[1].len().max(2) - 2)..].parse().unwrap(); if m_mod_100 == 0 { println!("1"); } else { println!( "{}", match n_mod_10 { 0 | 1 | 5 | 6 => n_mod_10, 2 => [6, 2, 4, 8][m_mod_100 % 4], 3 => [1, 3, 9, 7][m_mod_100 % 4], 4 => [6, 4][m_mod_100 % 2], 7 => [1, 7, 9, 3][m_mod_100 % 4], 8 => [6, 8, 4, 2][m_mod_100 % 4], 9 => [1, 9][m_mod_100 % 2], _ => unreachable!(), } ); } }