n = gets.to_s m = gets.to_s p (n.to_i**(m.chars[m.chars.size-1]).to_i) % 10