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