n = gets.to_i

inputs = gets.split.map(&:to_i)

min = inputs.inject(:+)
(1..(n - 1)).each do |i|
  diff = (inputs.slice(0, i).inject(:+) - inputs.slice(i, n - i).inject(:+)).abs
  min =  [diff, min].min
end

puts min
