from decimal import Decimal, getcontext def solve(): N = input() M = input() n = Decimal(N[-1]) m = Decimal(M) ctx = getcontext() ans = ctx.power(n, m, 10) print(ans) if __name__ == '__main__': solve()