local n=io.read("*n")
local a={}
local total=0
for i=1,n do
    a[i]=io.read("*n")
    total=total+a[i]
end

local total_i=0
local diff=10^19
for i=1,n-1 do
    total_i=total_i+a[i]
    diff=math.min(diff,math.abs(total-2*total_i))
end
print(diff)