Const
K:array[2..9,1..4] of integer=(
(2,4,8,6),
(3,9,7,1),
(4,6,4,6),
(5,5,5,5),
(6,6,6,6),
(7,9,3,1),
(8,4,2,6),
(9,1,9,1));
var
A,B,i,j:integer;
begin
Write('a='); Read(A);
Write('a='); Read(B);
i:=A mod 10;
if i<2 then Writeln(i)<br> else begin
j:=B mod 4;
if j=0 then j:=4;
Writeln(K[i,j])
end
end.