import Control.Monad solve :: Integral a => a -> a -> a solve n m | m' == 0 = (n' ^ 4) `mod` 10 | otherwise = (n' ^ m') `mod` 10 where n' = n `mod` 10 m' = m `mod` 4 main = do n <- readLn m <- readLn putStrLn $ show $ solve n m