from sys import set_int_max_str_digits set_int_max_str_digits(10 ** 6) N = int(input()) M = int(input()) print(pow(N, M, 10))