N = raw_input() M = raw_input() N = int(N) M = int(M) % 4 ANS = N**M % 10 print ANS