#![allow(unused_imports)] #![allow(non_snake_case)] use std::collections::HashMap; use std::collections::HashSet; use std::collections::VecDeque; #[allow(unused_macros)] macro_rules! read { ([$t:ty] ; $n:expr) => ((0..$n).map(|_| read!([$t])).collect::>()); ($($t:ty),+ ; $n:expr) => ((0..$n).map(|_| read!($($t),+)).collect::>()); ([$t:ty]) => (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::>()); ($t:ty) => (rl().parse::<$t>().unwrap()); ($($t:ty),*) => {{ let buf = rl(); let mut w = buf.split_whitespace(); ($(w.next().unwrap().parse::<$t>().unwrap()),*) }}; } #[allow(dead_code)] fn rl() -> String { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().to_owned() } fn main() { let n: u8 = { let tmp = read!(String); let tmp = tmp.into_bytes(); let tmp = tmp[tmp.len() - 1]; tmp - '0' as u8 }; let m = read!(String).into_bytes(); if m.len() == 1 && m[0] == '0' as u8 { println!("1"); return; } match n { 0 | 1 | 5 | 6 => { println!("{}", n); }, 2 | 3 | 7 | 8 => { let d = 4; let m = (m[m.len()-2] - '0' as u8) * 10 + (m[m.len() - 1] - '0' as u8) + d; let mut k = m % d; if k == 0 { k = d; } println!("{}", n.pow(k as u32) % 10); }, 4 | 9 => { let d = 2; let m = m[m.len() - 1] - '0' as u8 + d; let mut k = m % d; if k == 0 { k = d; } println!("{}", n.pow(k as u32) % 10); } _ => { unreachable!(); } } }