x,n = gets.split.map(&:to_i) a = gets.split.map(&:to_i) dp = Hash.new do |h,k| if k.odd? h[k] = (h[k / 2] ** 2) * h[1] % 1000003 else h[k] = (h[k / 2] ** 2) % 1000003 end end dp[0] = 1 dp[1] = x total = a.inject(0) {|s, v| (s + dp[v]) % 1000003 } puts total