N = int(input()) M = int(input()) ans = 1 while M > 0: if (M & 1) == 1: ans = ans*N % 10 M = M >> 1 N = (N * N) % 10 print(ans)