N = gets.to_i
weight = gets.split.map(&:to_i)
result = []
for i in 0..N-1 do
  left = weight[0..i]
  right = weight[i+1..N-1]
  result <<  (right.inject(:+) - left.inject(:+)).abs if left.any? && right.any?
end
p result.min