class Fixnum def power(x) result = 1 n = self while x > 0 result *= n if (x & 1).nonzero? n *= n x >>= 1 end result end end class Yukicoder EPS = 1_000_003 def initialize x, n = gets.chomp.split(' ').map(&:to_i) a = gets.chomp.split(' ').map(&:to_i) puts a.map{|i| x.power(i)}.inject(:+) % EPS end end Yukicoder.new