let f n = fun (s:string) -> if s.Length=1 then s.[0..] else s.[s.Length-n..] match ((stdin.ReadLine >> f 1)(),(stdin.ReadLine >> f 2)()) with | (_,"0") -> 1 | ("0",_) -> 0 | (n,m) -> (pown (int n) ((int >> fun n -> if n%4=0 then 4 else n%4) m))%10 |> stdout.WriteLine