n = gets.to_i
a = gets.split.map(&:to_i)
l_sum = 0
r_sum = a.inject(:+)
min = -1

(n-1).times do |i|
    l_sum += a[i]
    r_sum -= a[i]
    x = (l_sum - r_sum).abs
    min = x if(min == -1 || min > x)
end

puts min