# -*- coding: utf-8 -*- N = int(input()) M = int(input()) n = N%10 net_m = M%4 if net_m == 0: net_m = 4 ans = n**net_m % 10 print(ans)