# -*- coding: utf-8 -*- N, = map(str, raw_input().split()) M, = map(str, raw_input().split()) n = int(N[-1]) # mod 10 m = int(M[-2:]) # mod 100 m = m % 4 # mod 4 if m == 0 and M != '0': m = 4 print n ** m % 10