N = gets.to_i
A = gets.split().map(&:to_i)

min = 100000000000

(0..N-2).each do |i|
  left = A[0..i].inject(&:+)
  right = A[i+1..N-1].inject(&:+)
  if left > right
    min = [min, left-right].min
  else
    min = [min, right-left].min
  end
end

puts min



