#coding:utf-8 def main(): N = int(input()) M = int(input()) n = N % 10 m = M % 4 if not M % 4 == 0 else 4 ans = 1 if M == 0 else n ** m % 10 print(ans) if __name__ == '__main__': main()