a = int(input()) b = int(input()) c = [0] * 10 a, b = a % 10, b % 10 for i in range(10): c[i] = (a ** i) % 10 print(c[b])