end

#puts  "#{1}:#{sum_ary} "

  
place =0
sum =0
for i in 0..m-1
 # puts "?????¨??????:?????´???#{place}"
  t = gets.chomp.to_i
  before = place
  if place + t > n-1
    place = 100
  elsif place + t < 0
    place = 0
  else
    place += t
  end
  
    #puts "?§???????:?????´???#{place}"
  sub = sum_ary[place] - sum_ary[before]
 
  if sub <0
    sub =  sub * (-1)
  end
  sum += sub
 # puts "?§?????????¢#{sub},????§?????????¢#{sum}"
end

puts sum