
n = gets.to_i
w = gets.split.map {|x| x.to_i}

sum = 0
w.each { |v|
  sum += v
}

psum = 0
mind = sum
w.each { |v|
  d = (sum - psum) - psum
  if d.abs < mind
    mind = d.abs
  end
  psum += v
}

puts mind
