n = int(input()) m = int(input()) n %= 10 if m == 0: ans = 1 else: for i in range(10): t = ( n ** (i+1) ) % 10 if t == n and i != 0: f = i break m = m % f ans = (n**m)%10 print(ans)