import qualified Data.Char as C main :: IO () main = do n <- (C.digitToInt . last) <$> getLine m <- readLn print $ solve n m solve :: Int -> Int -> Int solve n 0 = 1 solve 0 _ = 0 solve 1 _ = 1 solve 2 m = case m `mod` 4 of 0 -> 6 1 -> 2 2 -> 4 3 -> 8 solve 3 m = case m `mod` 4 of 0 -> 1 1 -> 3 2 -> 9 3 -> 7 solve 4 m = case m `mod` 2 of 0 -> 6 1 -> 4 solve 5 _ = 5 solve 6 _ = 6 solve 7 m = case m `mod` 4 of 0 -> 1 1 -> 7 2 -> 9 3 -> 3 solve 8 m = case m `mod` 4 of 0 -> 6 1 -> 8 2 -> 4 3 -> 2 solve 9 m = case m `mod` 2 of 0 -> 1 1 -> 9