n = int(input()) m = int(input()) if m ==0: print(1) elif m%4==0: print(n**4%10) else: print(n**(m%4)%10)