# -*- coding: utf-8 -*- N = int(input()) M = int(input()) ans = 1 for i in range(M): ans = (ans*N) % 10 print(ans)