n = int(input()) m = int(input()) mod = 10 ans = pow(n,m,mod) print(ans)