N = gets.strip.to_i
a = gets.strip.split(' ').map(&:to_i)

diff = []
a.each_with_index do |v, index|
  left = a[0..index].inject(&:+)
  right = a[index+1..N].inject(&:+)
  next if right.nil?
  diff << (right - left).abs
end

puts diff.sort!.first