# frozen_string_literal: true

n = gets.to_i
w = gets.split.map(&:to_i)

total = w.reduce(:+)
sum = 0
min = total
w.each do |e|
  sum += e
  total -= e
  diff = (total - sum).abs
  min = diff if min > diff
end
puts min
