import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()[-1]) m=int(input()[-1]) print(pow(n,m,10))