n = int(input()) m = int(input()) n %= 10 a = 1 while m > 0: if m % 2 == 1: a = a * n % 10 n = n * n % 10 m = m // 2 print(a)