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