N = input() M = "0" + input() n = int(N[-1]) m = int(M[-2:]) print(pow(n, m, 10))