N = gets.chomp.to_i
W = Array.new(N)
sum = 0

str = gets.split
for x in 0...N
  W[x] = str[x].to_i
  sum += W[x]
end

half = (sum+1)/2
s1 = 0
s1a = 0
s1b = 0
i = 0
while s1 < half
  s1a = s1
  s1 += W[i]
  i += 1
end
s1b = s1

sub1 = sum - s1a*2
sub2 = sum - (sum-s1b)*2

if sub1 < sub2
  puts sub1
else
  puts sub2
end