a = gets.chop b = gets.chop n = a.to_i m = b.to_i if m == 0 then puts 1 return 0 end n %= 10 m %= 4 if m == 0 then m = 4 end puts n ** m % 10