class Fixnum MOD = 10 def power(x) result = 1 n = self while x > 0 result = (result * n) % MOD if (x & 1).nonzero? n = (n * n) % MOD x >>= 1 end result end end class Yukicoder def initialize n = gets.chomp.to_i m = gets.chomp.to_i puts n.power(m) % 10 end end Yukicoder.new