N = input() M = input() n = int(N[-1]) m = int(M) print(pow(n, m, 10))