x, N = gets.chomp.split.map(&:to_i) @devider = 1000003 list = gets.chomp.split.map{ |i| i.to_i % (@devider - 1) } dp = Array.new(@devider, -1) x %= @devider def my_pow(n, idx) res = 1 if idx > 0 res = my_pow(n*n % @devider, idx/2) res = res * n % @devider if idx & 1 == 1 end return res % @devider end result = 0 list.each do |l| if dp[l] == -1 dp[l] = my_pow(x, l) end result += dp[l] end p result % @devider