N = list(map(int, list(input()))) m = int(input()) print(pow(N[-1], m, 10))