N=int('1'+('0'+input())[-2:]) M=int('1'+('0'+input())[-2:]) n=1 if M==100 else pow(N,M,10) print(n)