n = gets.chomp.split[0].to_i
w = gets.chomp.split(" ").map(&:to_i)


left = []
right = []

l = 0
r = 0

for i in 1..n-1
    l += w[i-1]
    r += w[-i]
    left.push(l)
    right.push(r)
end
right.reverse!

ans = w[0] + r
for i in 1..n-1
    dif = (right[i-1] - left[i-1]).abs
    if dif < ans 
        ans = dif
    end
end

p ans