d = [[0],[1],[2,4,8,6],[3,9,7,1],[4,6],[5],[6],[7,9,3,1],[8,4,2,6],[9,1]] main=do [n,m]<-getContents>>=return.map(read::String->Integer).lines let dd = d!!(fromIntegral(n`mod`10)) print$if m==0 then 1 else dd!!(fromIntegral((m-1)`mod`(fromIntegral(length dd))))