n = gets.to_i
arr = gets.split.map(&:to_i)
res_arr = []
1.upto(n) do |t|
  lt_arr = []
  gt_arr = []
  arr.each_with_index do |e, i|
    if i <= t
      lt_arr << e
    else i > t
      gt_arr << e
    end
  end
  res_arr << (lt_arr.inject(:+) - gt_arr.inject(:+)).abs unless lt_arr.empty? || gt_arr.empty?
end
puts res_arr.min