import Control.Applicative import Control.Monad import qualified Data.ByteString.Char8 as B import Data.Maybe (fromJust) import Text.Printf import Debug.Trace pow a 0 = 1 pow a b | even b = pow (a*a `mod` 10) (b `div` 2) | otherwise = a * pow (a*a `mod` 10) (b `div` 2) `mod` 10 main = do n <- fst . fromJust . B.readInteger <$> B.getLine m <- fst . fromJust . B.readInteger <$> B.getLine print $ pow n m `mod` 10