n,*b=$<.read.split.map &:to_i h=Hash.new(0) c=b.pop(n) c.zip(b).each{|i,d|h[i]+=d} puts h[0]