n = int(input()) m = int(input()) n %= 10 mm = m % 4 mm += 3 base = n for i in range(mm): n *= base if m == 0: print(1) else: print(n % 10)