var
n,i,len,k:longint;
s:string;
begin
readln(n);
k:=1;
for i:=1 to n do
begin
k:=k*n;
str(k,s);
len:=length(s);
val(s[len],k);
end;
writeln(k);
end.
var
n,i,k:longint;
begin
readln(n);
k:=1;
for i:=1 to n do
k:=(k*n) mod 10;
writeln(k);
end.