n=gets.chomp.to_i
weights=gets.chomp.split.map(&:to_i)
total=0
array=[]

weights.each do |i|
  total += i
end

(0..(n - 1)).each do |t|
  s_1=0
  (0..t).each do |i|
    s_1 += weights[i]
  end
  s_2= total - s_1
  if s_1 > s_2
    s=s_1 - s_2
  else
    s=s_2 - s_1
  end
  array << s
end

array_=array.sort

print array_[0]
