def solve(k,a,b)
  if k==$n
    return (a-b).abs
  end
  return [solve(k+1,a+$ps[k],b),solve(k+1,a,b+$ps[k])].min
end

loop do
  $n = gets.to_i
  break if $n==0
  $ps = gets.split.map(&:to_i)
  puts solve(0,0,0)
end