N = gets.chomp.to_i
w = gets.chomp.split(" ").map(&:to_i)

def sum(ary)
  a = 0
  ary.map{|e|
    a += e
  }
  a
end


ans = sum(w)

for t in 1...N do
  ans = [ans, ( sum(w[t+1..N-1]) - sum(w[0..t]) ).abs ].min
end

puts ans
