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