R = [1, 1, 4, 4, 2, 1, 1, 4, 4, 2] N = int(input()) % 10 M = int(input()) M = (M - 1) % R[N] + 1 ans = N ** M ans %= 10 print(ans)