n = int(input()) m = int(input()) n = n % 10 print(pow(n,m,10))