import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,M = map(int,read().split()) N %= 10 if M > 100: M = M % 4 + 100 answer = pow(N,M,10) print(answer)