N, M = int(raw_input()), int(raw_input()) print pow(N, M, 10)