n = io.read("*n")
w = {}
sum = 0
for i = 1, n do
  w[i] = io.read("*n")
  sum = sum + w[i]
end
l = 0
ret = sum
for i = 1, n - 1 do
  l = l + w[i]
  ret = math.min(ret, math.abs(sum - l - l))
end
print(ret)
